I have asked this on StackOverflow but this could be a better channel.
How to reproduce the issue
Build an image based on this Dockerfile
FROM continuumio/miniconda3
RUN apt-get install -y npm nodejs-legacy && \
npm install -g configurable-http-proxy && \
pip install jupyterhub dockerspawner jupyter_client
EXPOSE 8000
CMD jupyterhub --no-ssl
then run docker run -t tmp
What you expected to happen
127.0.0.1:8000 is accessible from outside the container
What actually happens
127.0.0.1:8000 is not accessible from browsers.
docker ps shows that port 8000 is open.
~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7e51cdf9f234 tmp "/usr/bin/tini -- /bi" 7 seconds ago Up 5 seconds 8000/tcp boring_chandrasekhar
netstat doesn't agree.
~ netstat -lt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:ssh *:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
Hi @FabHan. Even though you EXPOSE port 8000 in your Dockerfile, you still need to map it to an external port at runtime with a command like docker run -p 8000:8000 -t tmp.
The EXPOSE in the Dockerfile only enables you to use the shorthand docker run -t -P tmp where the capital P tells docker to automatically map all exposed ports to external ports.
Thank you. That solves my problem.
Most helpful comment
Hi @FabHan. Even though you
EXPOSEport 8000 in your Dockerfile, you still need to map it to an external port at runtime with a command likedocker run -p 8000:8000 -t tmp.The
EXPOSEin the Dockerfile only enables you to use the shorthanddocker run -t -P tmpwhere the capital P tells docker to automatically map all exposed ports to external ports.