# docker run: Usage, Options & Common CI Errors

> How docker run works: starting a container from an image, port and volume mapping, env vars, --rm cleanup, and the run failures common in CI.

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

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

| Flag | Does |
| --- | --- |
| --rm | Remove the container when it exits |
| -d, --detach | Run in the background |
| -it | Interactive + TTY (combine -i and -t) |
| -p host:container | Publish a port |
| -v src:dst | Bind-mount or volume |
| -e KEY=val | Set an environment variable |
| --name | Assign a container name |
| -w | Working 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.

## FAQ

### docker run: Usage, Options & Common CI Errors?

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

---

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
