LinuxCommandLibrary

docker-container-run

create and start a new container

TLDR

Run a container

$ docker container run [image]
copy
Run interactively
$ docker container run -it [image] /bin/bash
copy
Run in background
$ docker container run -d [image]
copy
Run with port mapping
$ docker container run -p [8080:80] [image]
copy
Run with volume mount
$ docker container run -v [/host/path:/container/path] [image]
copy
Run with name
$ docker container run --name [mycontainer] [image]
copy
Run and remove on exit
$ docker container run --rm [image]
copy
Run with environment variable
$ docker container run -e [VAR=value] [image]
copy

SYNOPSIS

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

DESCRIPTION

docker container run creates and starts a new container from a specified image, combining the functionality of docker container create and docker container start into a single command. This is the most common way to launch containers in Docker.
When executed, Docker pulls the image if not locally available, creates a container with the specified configuration, and starts it. The command supports extensive configuration options for networking, storage, resource limits, and runtime behavior. Using --rm ensures ephemeral containers are cleaned up automatically, while -d enables daemon mode for background services.
This command is equivalent to the legacy docker run command.

PARAMETERS

-d, --detach

Run in background.
-i, --interactive
Keep STDIN open.
-t, --tty
Allocate pseudo-TTY.
-p, --publish hostPort:containerPort
Publish port.
-v, --volume src:dest
Bind mount a volume.
-e, --env var=value
Set environment variable.
--name name
Assign container name.
--rm
Remove container on exit.
--network network
Connect to network.
-w, --workdir dir
Working directory inside container.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community