Docker Env and Ports
Wire configuration and networking without editing images.
- docker env
- env-file
- publish port
- docker secrets
- port conflict
Docker Env and Ports
Wire configuration and networking without editing images.
Commands
| Command | What it does | |
|---|---|---|
docker run -e NODE_ENV=production app:v1 | Single env var | |
docker run --env-file .env app:v1 | Whole env file | |
docker run -p 8080:80 app:v1 | Publish a port to the host | |
docker run -P app:v1 | Publish all EXPOSEd ports randomly | |
| `docker exec <c> env | sort` | Verify what the container actually sees |
Example
docker run -d --env-file .env -p 8080:8080 --name api app:v1
docker exec api env | sort | head
FAQ
Where should secrets go?
Not in images: use --env-file from a vault-rendered file, or Docker secrets under Swarm; never bake tokens into layers.
Port already allocated?
Another container owns the host port — docker ps shows mappings; pick a free host port or stop the clash.
คำถามที่พบบ่อย
Where should secrets go?
Not in images: use --env-file from a vault-rendered file, or Docker secrets under Swarm; never bake tokens into layers.
Port already allocated?
Another container owns the host port — docker ps shows mappings; pick a free host port or stop the clash.
Docker
Docker Install and Setup
Verify the Docker engine, configure context, and check versions.
Docker Images
Pull, list, tag, inspect, and remove images confidently.
Docker Containers
Run, list, stop, and clean up containers in daily work.
Docker Run Options
The flags that matter: detach, ports, env, volumes, limits.