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:
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.
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 is a Docker command. In other words, a command given to the
executable. Typically, the first argument given to the
docker executable is the Docker command.
The last . is an argument to the
build command instructs Docker to build a Docker image from a
Dockerfile. To use the
you must tell it what Dockerfile to build the image from. You do so via an argument to the
build command. Here is a
build command example:
docker build .
. arguments means "use the Dockerfile found in the current directory".
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:
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
run command is used to run a Docker container based on a given Docker image.
As argument to
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
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
ps command shows what Docker containers you have running currently.
Here is an example of the
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
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
ps list of Docker containers.