Docker EXPOSE and publishing ports
Answer: EXPOSE records which network ports the container listens on at runtime. It does not actually publish the port. Publish with docker run -p, or use --expose / -P as documented on the run page.
Examples
FROM python:3.13-slim
EXPOSE 8000
CMD ["python", "app.py"]
docker run -p 8000:8000 myapp
Rules
- TCP is the default protocol if you do not specify one. You can also specify UDP.
- Use
-p/--publishto map a container port onto the host.
See also
Claims
- id: C1 claim: EXPOSE does not itself publish a port. source: S1 evidence: "The EXPOSE instruction doesn't actually publish the port"
- id: C2 claim: TCP is the default protocol when none is given. source: S1 evidence: "The default is TCP if you don't specify a protocol"
- id: C3 claim: The -p / --publish flag maps a port to the host. source: S2 evidence: "flag lets you explicitly map a single port"
Sources
- [S1] Dockerfile reference. Docker docs. https://docs.docker.com/reference/dockerfile/ . License: Apache-2.0. Accessed 2026-11-18.
- [S2] Running containers. Docker docs. https://docs.docker.com/engine/reference/run/ . License: Apache-2.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs, Dockerfile reference; Docker docs, Running containers. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs, Dockerfile reference; Docker docs, Running containers. Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker EXPOSE and publishing ports." iinventedlight Library, iil:note:s0ca87t4, version of 2026-11-18. https://iinventedlight.com/library/notes/docker-expose/. License: CC-BY-4.0.
@misc{iil_note_s0ca87t4,
author = {{iinventedlight}},
title = {{Docker EXPOSE and publishing ports}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/docker-expose/},
note = {Permanent ID iil:note:s0ca87t4. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-expose.md.