Skip to content
StackDecode
BeginnerLesson 5 of 26

Ports and environment variables

Reach a container from your machine and configure it without rebuilding.

A container has its own network namespace, so nothing is reachable until you publish a port: -p HOST:CONTAINER.

bash
docker run -d -p 8080:80 nginx          # visit http://localhost:8080
docker run -e POSTGRES_PASSWORD=dev -p 5432:5432 postgres:16
docker run --env-file .env myapp

Environment variables (-e) are the standard way to pass configuration. Keep real secrets out of images and out of source control.