# docker run Command Reference

> Reference for docker run in CI: --rm, -e, -v, --network, -w, and --entrypoint flags for creating and starting a container from an image in pipelines.

Source: https://latchkey.dev/learn/command-reference/docker-run-command-reference  
Updated: 2026-06-26

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

```shell
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.

## FAQ

### docker run Command Reference?

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.

### 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.

---

Latchkey runs CI/CD that repairs its own failures. Agent entry points: https://latchkey.dev/agent.txt, https://latchkey.dev/openapi.json, https://latchkey.dev/llms.txt
