Skip to content

Docker: Run containers

3 Docker commands: Run containers. Click a command to see what each part does.

Index
3 items
Click a command to see what each part does.

Run containers3

  • docker run -d --name <name> -p <host-port>:<container-port> <image>:<tag>Run a service in the background with a port and a name

    What each part does

    1. docker runcreate and start a container
    2. -d--detach: run in the background and print the ID
    3. --name <name>give it a fixed name instead of a random one
    4. -p <host-port>:<container-port>publish a container port on the host (binds all interfaces; use 127.0.0.1:<host-port>:… for local only)
    5. <image>:<tag>image to run (pin a tag, avoid latest)
  • docker run -it --rm <image> shThrow-away interactive container

    What each part does

    1. -itinteractive + terminal
    2. --rmdelete the container (and anonymous volumes) when it exits
    3. shcommand to run instead of the image default
  • docker run -d -e <KEY>=<value> --env-file .env -v <host-path>:<container-path>:ro -m 512m --cpus 1 --restart unless-stopped <image>Env vars, volume and limits

    What each part does

    1. -e <KEY>=<value>set one environment variable
    2. --env-file .envload KEY=value lines from a file
    3. -v <host-path>:<container-path>:robind-mount a host folder, read-only
    4. -m 512mmemory limit (exceeding it → OOM kill, exit 137)
    5. --cpus 1at most one CPU worth of time
    6. --restart unless-stoppedrestart automatically unless you stopped it yourself

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…