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.1
Testcontainers 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

Taught in

References