Docker Engine 29 reference · Containers
docker run Command (Docker CLI)
Create and start a container from an image, with options for ports, environment, volumes, names and cleanup.
Docker Engine 29
Syntax
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Parameters
| Parameter | Description |
|---|---|
--rm |
Remove the container when it exits. |
-d |
Run in the background and print the container ID. |
--name NAME |
Give the container a name. |
-e KEY=VALUE |
Set an environment variable. |
-p HOST:CONTAINER |
Publish a container port on the host. |
-v SOURCE:TARGET |
Mount a volume or host path. |
Examples
docker run --rm alpine:3.24 echo hello from a container
docker run --rm -e NAME=Ana alpine:3.24 sh -c 'echo "hi $NAME"'
Output
hello from a container hi Ana
Run this on your computer — see “Get Started” for setup.
docker run -d --name rc-ref-run alpine:3.24 sleep 300 > /dev/null
docker ps --filter name=rc-ref-run --format '{{.Names}}: {{.State}}'
docker rm -f rc-ref-run > /dev/null
Output
rc-ref-run: running
Run this on your computer — see “Get Started” for setup.
The container lives as long as its main process. Arguments after the image replace the image's CMD. Use --rm for one-off commands so stopped containers don't pile up.
Related
docker ps· List containers: running ones by default, all with -a, filtered and formatted for scripts with --filter and --format.docker exec· Run an extra command inside a running container, for example a shell for debugging or a one-off task.docker rm· Remove one or more stopped containers and their writable layers; -f stops and removes running ones too.- Running Containers · tutorial