docker run Command Reference
Create and start a container from an image.
docker run is docker create plus docker start in one command. It pulls the image if missing, creates a writable layer, and runs the image command or one you pass. In CI you almost always want --rm so containers do not pile up.
Common flags
--rm- remove the container automatically when it exits-e KEY=value- set an environment variable (repeatable)-v src:dst- bind-mount a host path or named volume-w, --workdir- working directory inside the container--network- attach to a network, e.g. host or a named network--entrypoint- override the image ENTRYPOINT-d, --detach- run in the background and print the container ID
Example
docker run --rm \
-e CI=true \
-e NPM_TOKEN=${NPM_TOKEN} \
-v "${PWD}":/app \
-w /app \
--entrypoint sh \
node:20 -c "npm ci && npm test"In CI
Avoid -it in pipelines: the -t (TTY) flag causes "the input device is not a TTY" with no terminal attached. Always pass --rm so ephemeral test containers are cleaned up. Mount the workspace with -v and set -w to run tools against your checked-out code.
Key takeaways
- Use --rm in CI so one-shot containers are removed on exit.
- Drop the -t TTY flag in non-interactive pipelines to avoid "not a TTY" errors.
- --entrypoint overrides the image default to run an arbitrary command.