Intermediate Docker
Mike Metzger
Data Engineer
EXPOSE
command<number>
, <number>/tcp
, or <number>/udp
EXPOSE 80
or EXPOSE 80/tcp
-p
or -P
options to docker run
to make the ports available outside the container-P
option will automatically map an ephemeral port to the exposed port(s). Must use docker ps -a
to see which ports are mapped.-p<host port>:<container port>
allows use of specific ports.# Dockerfile
FROM python:3.11-slim
ENTRYPOINT ["python","-mhttp.server"]
# Let the Docker engine know
# port 8000 should be available
EXPOSE 8000
docker run pyserver
docker ps -a
CONTAINER ID IMAGE ... PORTS NAMES
8c3d320255ae pyserver ... 8000/tcp angry_chaum
docker run -P pyserver
docker ps -a
CONTAINER ID IMAGE ... PORTS NAMES
6bb458ef25da pyserver ... 0.0.0.0:55001->8000/tcp beautiful_lamarr
docker inspect
provides a lot of informationdocker inspect <id>
"NetworkSettings": {
"Bridge": "",
"Ports": {
"8000/tcp": [{
"HostIp": "0.0.0.0",
"HostPort": "55001"
}]
},
...
Intermediate Docker