Here is a basic Docker NGINX image:
FROM nginx:alpine
COPY src /usr/share/nginx/html
EXPOSE 80
The image's metadata includes the exposed port:
> docker inspect --format '{{json .Config.ExposedPorts}}' ...
{"80/tcp":{}}
But when running it with docker run --publish-all
the server is not accessible.
It must be run with docker run --publish 80:80
.
But isn't the point of EXPOSE
to document the image's port so they can be published without having to be explicitly listed thanks to --publish-all
?
The --publish-all
flag publishes the "exposed ports to ephemeral ports".
So, you'll get something like:
docker container inspect nginx --format=json \
| jq -r '.[0].NetworkSettings.Ports'
{
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "32769"
}
]
}
Where, in this case, the container port 80 is mapped to the host's 32769 (not 80).