port publishing
Forwarding a port on the host to a port inside a container so the service can be reached from outside.
Publishing on all interfaces can expose a development database to the whole network.
In more detail
A container has its own network, so its ports cannot be reached from the host until they are published. Tools can publish to a fixed host port or to a random free one and report which was chosen.
Examples
docker run -d --name taskapi-demo -p 18080:8000 taskapi:0.1Testcontainers maps the database port to a random host port and Spring reads it.In this course: Container test libraries usually publish the dependency on a random free host port and tell the test which one, so parallel runs never collide. Point the client at that mapped port, not at a hard-coded one.Related terms
- port — A number from 1 to 65535 that picks out one service on a machine, such as 22 for SSH or 80 for plain web traffic.
- EXPOSE — The Dockerfile instruction that documents which port the application listens on; it does not publish anything.
- bind address — The network address a server listens on, which decides who can connect to it.
- network namespace — The namespace that gives a process its own network interfaces, addresses, routes and ports.
- Testcontainers — A family of libraries that start real dependencies such as databases in throwaway containers for the length of a test.
- container — A running program that has been fenced off from the rest of the computer so it only sees its own files, network and processes.
Taught in
- Commands, Logs, Exec And Exit Codes — Docker Architecture & Production Containers
- Run The Spine Service And Publish Its Port — Docker Architecture & Production Containers
- Build Context, Dockerignore And Your First Dockerfile — Docker Architecture & Production Containers
- ARG, ENV, LABEL, EXPOSE And VOLUME — Docker Architecture & Production Containers
- Authenticate, Tag, Push And Pull From A Registry — Docker Architecture & Production Containers
- Scan, Patch And Inspect The Software Supply Chain — Docker Architecture & Production Containers
- Ephemeral Filesystems And Named Volumes — Docker Architecture & Production Containers
- Bind Mounts, Permissions And Backups — Docker Architecture & Production Containers
- Bridge Networks, DNS And Container Communication — Docker Architecture & Production Containers
- Port Publishing, Localhost And Network Troubleshooting — Docker Architecture & Production Containers
- Define The Service And Database With Compose — Docker Architecture & Production Containers
- Health Checks, Dependencies And Reliable Startup — Docker Architecture & Production Containers
- Development Overrides, Hot Reloading And Debuggers — Docker Architecture & Production Containers
- Integration Tests, Test Data And Compose Cleanup — Docker Architecture & Production Containers
- Diagnose Crashes, Resource Limits And Unhealthy Containers — Docker Architecture & Production Containers
- Build, Test And Promote The Same Image In CI — Docker Architecture & Production Containers
- Harden And Deliver The Complete Service Stack — Docker Architecture & Production Containers
- Database Integration With Testcontainers — Modern Java: Virtual Threads & High-Throughput Services
- Integration Testing With Containers — Automated Testing, TDD & Quality Engineering