Choose the correct explanation of the EXPOSE instruction in a Dockerfile.
Think about whether EXPOSE opens ports by itself or just informs about them.
The EXPOSE instruction in a Dockerfile is used to document which ports the container will listen on at runtime. It does not publish or open these ports automatically; that requires additional options when running the container.
Given a Dockerfile with EXPOSE 8080 and a container started without port mapping, what does docker port <container_id> show?
Dockerfile: FROM nginx EXPOSE 8080 Commands: docker build -t test-expose . docker run -d --name test-container test-expose docker port test-container
Consider if docker run without -p or --publish publishes ports.
Without explicit port publishing using -p or --publish, the docker port command shows no output because the container ports are not mapped to the host.
Select the Dockerfile snippet that correctly exposes ports 80 and 443.
Think about how Dockerfile instructions handle multiple lines versus single line with multiple ports.
Dockerfile supports multiple EXPOSE instructions, each exposing one or more ports. Using separate EXPOSE lines for each port is correct. The syntax EXPOSE 80 443 is valid because EXPOSE expects one port per instruction or multiple ports separated by spaces but not as a list or string.
You have a Dockerfile with EXPOSE 5000 and run the container with docker run myapp. You try to access the service on port 5000 from your host but fail. What is the most likely reason?
Remember what EXPOSE does and what is needed to make ports accessible from outside the container.
EXPOSE only documents ports but does not publish them. To access a container's port from the host, you must publish it using -p host_port:container_port when running the container.
In a multi-stage Dockerfile, where should you place the EXPOSE instruction to correctly document the ports for the final image?
Think about which stage produces the final image used to run containers.
EXPOSE should be used in the final stage of a multi-stage Dockerfile to document the ports that the final image will listen on. Ports used only during build stages do not need to be exposed.