Top 10 options for the docker run CLI command

Aug 31, 2018 · 3 min read

An explanation of 10 commonly used options for the docker run CLI command.

The docker run CLI command has around 100 options, including -d, -i, -t, -v, and -w. This tutorial will explain 10 of the most common ones, as well as links to learn more about using them. Below is an example of docker run with the options covered in this article.

docker run \
  --rm \
  --detach \
  --env KEY=VALUE \
  --ip \
  --publish 3000:3000 \
  --volume my_volume \
  --name my_container \
  --tty --interactive \
  --volume /my_volume \
  --workdir /app \
  IMAGE bash

The docker run CLI command

This creates a container based on an image. It executes your chosen command and arguments in a new container with the configuration provided by your given options.

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command. — docker run extended description | Docker Documentation

Similar Docker CLI commands

The docker run command is similar to docker exec, which is to run a command in an existing container.

A stopped container can be restarted with all its previous changes intact using docker start. Use the following command to view a list of all containers.

docker ps -a

Top 10 options

The top 10 docker run options in alphabetical order.

1. --detach, -d

By default a Docker container is run attached to local standard input, output, and error streams. The -d, --detach option runs the container in the background of your terminal session so its output is not displayed.

2. --entrypoint

Set or overwrite the default entrypoint command for the image. The entrypoint sets the command and parameters that will be executed first when a container is run. Any any commands and arguments passed at the end of the docker run command will be appended to the entrypoint.

3. --env, -e

Set an environment variable using a KEY=VALUE pair. If you have environment variables in file, you can pass in the file path to the option --env-file.

4. --ip

Declare an IP address, for example --ip=

5. --name

Assign a name to the container, --name my_container

6. --publish, -p, --publish-all, -P

These publish port mappings between the container and host that are defined in an image’s Dockerfile or by using the expose option, --expose. The option --publish, -p publishes a container’s port(s) to the host, while --publish-all, -P publishes all exposed ports.

7. --rm

Automatically remove the container when it exits.

8. --tty, -t

Allocate a virtual terminal session within the container. This is commonly used with the option --interactive, -i, which keeps STDIN open even if running in detached mode.

9. --volume, -v

Mount a volume -v /my_volume. If you are new to volumes then find out more in Docker’s guide to Volumes.

10. --workdir, -w

State the working directory inside the container. For example, if you copy your files into an app folder within your container then you may want to set the working directory to app.

Find out more

If you want to see the full list of docker run options, they are listed in Docker’s run CLI documentation along with other useful examples. There are many great Docker tutorials online, such as Docker Con EU’s Hands-On Labs.