Docker Commands

Jakob Jenkov
Last update: 2019-10-27

The Docker commands are how you interact with Docker. You use Docker commands to build a Docker image, run a Docker container, send a Docker image to a remote Docker registry etc. In this Docker command tutorial I will describe some of the most commonly used Docker commands.

Docker has many commands, and I will not be explaining all of them in this Docker command tutorial. You can find a full reference of the Docker command line interface at:

Docker command line reference

Please note, that depending on how you install Docker on your Linux system, you might need to prefix all of the commands in this tutorial with sudo to run them using superuser privileges. For instance,

sudo docker build .

... instead of just:

docker build .

Docker Command Line Tool

When you install Docker on a Linux computer a command line executable named docker is installed on the Linux computer. The docker command line executable is executed via the Linux command line.

The docker command line executable can take many different arguments which acts as commands to Docker. Here is an docker command example:

docker build .

This example consists of the docker command line executable, the build argument and the . argument.

The build argument is a Docker command. In other words, a command given to the docker executable. Typically, the first argument given to the docker executable is the Docker command.

The last . is an argument to the build command.

docker build

The docker build command instructs Docker to build a Docker image from a Dockerfile. To use the docker build command you must tell it what Dockerfile to build the image from. You do so via an argument to the docker build command. Here is a docker build command example:

docker build .

The . arguments means "use the Dockerfile found in the current directory".

docker images

The docker images command lists all the Docker images you have in your computer's local Docker image registry. Here is an example of the docker images command:

docker images

The output from running the above command will look similar to this:

REPOSITORY       TAG        IMAGE ID        CREATED          SIZE
hello-world      latest     fce289e99eb9    9 months ago     1.84kB

docker run

The docker run command is used to run a Docker container based on a given Docker image. As argument to docker run you pass the name or image ID of the Docker image you want to run a container based on. Here is an example of running a Docker container:

docker run hello-world

This example will run a Docker container based on the hello-world Docker image, as listed in the previous section about the docker images command.

To run a Docker container based on the same Docker image, but using its image ID instead of image name, use this command:

docker run fce289e99eb9

docker ps

The docker ps command shows what Docker containers you have running currently. Here is an example of the docker ps command:

docker ps

Note, that some Docker containers may shut down as soon as their have done their work. The Docker image hello-world is an example of that. Docker containers based on the hello-world Docker image write out a text to the console, and then shut down. Such a container will not be visible for very long in the docker ps list of Docker containers.

Jakob Jenkov

Featured Videos

Java Generics

Java ForkJoinPool

P2P Networks Introduction



















Close TOC
All Tutorial Trails
All Trails
Table of contents (TOC) for this tutorial trail
Trail TOC
Table of contents (TOC) for this tutorial
Page TOC
Previous tutorial in this tutorial trail
Previous
Next tutorial in this tutorial trail
Next