Skip to content
Latchkey

docker run: Usage, Options & Common CI Errors

Create and start a container from an image, with the flags you actually use.

docker run creates a container from an image and starts it. It is by far the most-used Docker command. This page covers the essential flags and the run errors that show up in CI.

What it does

docker run is docker create plus docker start in one step. It pulls the image if missing, creates a writable container layer, and runs the image command (or a command you pass).

Common usage

Terminal
docker run --rm -it ubuntu:22.04 bash
docker run -d -p 8080:80 --name web nginx
docker run --rm -e NODE_ENV=test -v "$PWD":/app -w /app node:20 npm test
docker run --rm --memory=512m --cpus=1 myapp

Options

FlagDoes
--rmRemove the container when it exits
-d, --detachRun in the background
-itInteractive + TTY (combine -i and -t)
-p host:containerPublish a port
-v src:dstBind-mount or volume
-e KEY=valSet an environment variable
--nameAssign a container name
-wWorking directory inside the container

Common errors in CI

Passing -it in CI causes "the input device is not a TTY" because there is no terminal attached. Drop -t (use -i alone, or neither) in non-interactive pipelines. Another: "docker: Error response from daemon: ... port is already allocated" when a previous container still holds the port - give it a unique --name and run with --rm, or stop the old container first.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →