The EXPOSE
directive in a Dockerfile serves as documentation to indicate which ports the containerized application listens on internally. It does not automatically make these ports accessible from the host machine.
When you run a container using docker run -d my-image
without specifying any port mappings (using the -p
flag), Docker does not publish any of the container's ports to the host. This means the application running inside the container on port 5000 is not accessible from the host machine.
Accessing the Application: To make the application accessible from the host, you need to explicitly map the container's port to a port on the host using the -p
flag. For example:
docker run -d -p 5000:5000 my-image
*****
A) The EXPOSE
instruction does not automatically publish the port to the host. You must use the -p
flag to do so.
B) While EXPOSE
does indicate that the port is available within the Docker network, it does have an effect in terms of documentation and potential use in automated setups, but it does not automatically expose the port to the host.
C) The -d
flag simply runs the container in detached mode and does not influence port publishing or assign random high-numbered ports to the host. The container runs in the background. Your terminal is not attached to the container's process - you can close your terminal, and the container will continue to run.