Docker Run Options

The flags that matter: detach, ports, env, volumes, limits.

  • docker run
  • docker env
  • docker ports
  • docker volumes
  • resource limits

Docker Run Options

The flags that matter: detach, ports, env, volumes, limits.

Commands

CommandWhat it does
docker run -d --name api app:v1Detached with a stable name
docker run -p 8080:80 -e PORT=80 app:v1Publish port and set env var
docker run --env-file .env app:v1Load many env vars from a file
docker run -v data:/data app:v1Persist /data in a named volume
docker run --memory 512m --cpus 1 app:v1Cap memory and CPU
docker run --rm -it ubuntu:24.04 bashThrowaway interactive shell

Example

docker run -d --name api --env-file .env -p 8080:8080 --memory 512m app:v1
docker ps --filter name=api

FAQ

-p host:container โ€” which side is which?

Left is the host port you open, right is the container port the app listens on.

When should I use --rm?

For one-off commands (migrations, shells): the container self-deletes on exit, no clutter.

Soalan Lazim

-p host:container โ€” which side is which?
Left is the host port you open, right is the container port the app listens on.
When should I use --rm?
For one-off commands (migrations, shells): the container self-deletes on exit, no clutter.

Docker