docker-run

create and start containers from images

TLDR

Run a container interactively
$ docker run -it [image] [bash]
Run container in background
$ docker run -d [image]
Run with port mapping
$ docker run -p [8080:80] [image]
Run with volume mount
$ docker run -v [/host/path:/container/path] [image]
Run with environment variables
$ docker run -e [VAR=value] [image]
Run with automatic removal on exit
$ docker run --rm [image]
Run with custom name
$ docker run --name [container_name] [image]
Run with memory limit
$ docker run -m [512m] [image]

SYNOPSIS

docker run [options] image [command] [args]

DESCRIPTION

docker run creates and starts a new container from an image. It combines docker create and docker start into a single command, providing the primary way to launch containers.The command pulls the image if not present locally, creates a container from it, and starts execution. Options control resource allocation, networking, storage, and runtime behavior.Containers are isolated but can connect to host resources through port mapping, volume mounts, and network configuration. The -it flags enable interactive terminal access for debugging and exploration.

PARAMETERS

-d, --detach

Run container in background.
-it
Interactive with pseudo-TTY.
-p, --publish host:container
Publish container port to host.
-v, --volume host:container
Bind mount a volume.
-e, --env VAR=value
Set environment variable.
--name name
Assign container name.
--rm
Remove container on exit.
-m, --memory limit
Memory limit (e.g., 512m, 1g).
--cpus n
Number of CPUs.
--network network
Connect to network.
--restart policy
Restart policy: no, always, unless-stopped, on-failure.
-w, --workdir dir
Working directory inside container.
-u, --user user
Username or UID.
--entrypoint cmd
Override default entrypoint.

INSTALL

sudo apt install docker-cli
sudo dnf install docker-cli
sudo pacman -S docker
sudo apk add docker-cli
sudo zypper install docker
brew install docker
nix profile install nixpkgs#docker

CAVEATS

Containers run as root by default; use -u for non-root execution. Ports below 1024 require root on the host. Volumes with relative paths are created as Docker volumes, not bind mounts. Container filesystem changes are lost unless volumes are used.

HISTORY

docker run has been the fundamental Docker command since the initial release in 2013 by Solomon Hykes and dotCloud (later Docker, Inc.). The command's design draws from Unix philosophy and LXC container concepts. Options have expanded significantly to support enterprise features, orchestration, and security requirements.

SEE ALSO

docker(1), docker-build(1), docker-ps(1), docker-exec(1)

RESOURCES

Source code · Documentation