Installing and configuring Docker on Ubuntu

Installing and configuring Docker on Ubuntu

Author: HostZealot Team
2 min.

Modern infrastructure does not exist without microservices and containers. These technologies are great when it comes to running an application in processes isolated from resources. Docker has become a household name when it comes to containerization management. It's an application that makes it easy to manage application processes in containers.

What is a container? It is a structure that contains applications with all the required libraries and dependencies. This makes it possible to port the needed packages to other distributions without having to create a similar environment. Unlike hardware virtualization, containers are easy to port and require fewer resources. Most importantly, containers are completely independent of external distribution.

In this article, we will explain how Docker Community Edition works using Ubuntu 20.04 as an example. We will describe how to work with containers and images using concrete examples and show what Docker Compose is.

Recommended specifications for hardware

As for hardware recommendations, Docker has no hardware requirements. Considering that it is a virtualization utility, it all depends on the scale of applications that will be deployed inside the containers. There is one requirement for the "machine" – virtualization support.

Before proceeding with the installation, we suggest that you check if your environment meets the minimum system requirements:

  • 64-bit architecture;
  • kernel version 3.10.

Setting up Docker in Ubuntu

Earlier it was stated that we would use the Ubuntu server to set up Docker.

Installing Docker

We need the latest version of the utility. You don't have to check the Ubuntu repository because they don't always post the latest release of the software.

We suggest that you go straight to the official Docker registry. This requires adding a new batch source. To make sure that working files will be loaded, you will need to load the GPG key. After the manipulation is done, you can install the package.

First, update the list of packages on the device:

$ sudo apt update

Next, you will need to install software designed to make apt work properly over HTTPS:

$ sudo apt install apt-transport-https ca-certificates curl software-properties-common

Optionally, additional kernel software may be needed. This is necessary to enable the aufs file system to work with the utility containers. This way you can quickly detect changes and create Snapshots. These are read-only images.

$ sudo apt install linux-image-extra-$(uname -r) linux-image-extra-virtual

Add a GPG key for the Docker repository:

$ curl -fsSL | sudo apt-key add -

The following three commands are necessary to add the software repository directly to Ubuntu and then install Docker into the distribution.

$ sudo add-apt-repository "deb [arch=amd64] bionic stable"
$ sudo apt update && apt-cache policy docker-ce
$ sudo apt install -y docker-ce

In some cases, you may not be able to connect to a socket when starting Docker. To avoid this, add the user to the Docker group. Use the following command:

$ sudo usermod -aG docker $(whoami)

After these actions, the software will be installed, launched, and added to the autostart. You can additionally check the functionality with the following command:

$ sudo systemctl status docker

If daemon works correctly, a similar message will appear on the line:

$Output● docker.service - Docker Application Container Engine

    Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)

    Active: active (running) since Tue 2020-05-19 17:00:41 UTC; 17s ago

TriggeredBy: ● dockersocket


  Main PID: 24321 (dockerd)

      Tasks: 8

    Memory: 46.4M

    CGroup: /system.slice/docker.service

            └─24321 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

At this point, the installation is complete and the utility is ready to go. To fully use Docker, you will need an auxiliary tool called Docker Compose.

installing and configuring docker on ubuntu

Installing the Docker Compose utility

What is this software? Compose is a tool that helps you run several different containers. The utility uses service definitions to create fully customizable multi-container environments. They can share the network and external memory space. Run the following command sequence:

$ sudo curl -L "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

This command sets the correct permissions to execute docker-compose commands:

$ sudo chmod +x /usr/local/bin/docker-compose

Check that the software is up to date and confirm a successful installation:

$ docker-compose --version

If we see such a conclusion:


docker-compose version 1.29.2, build 5becea4c

So the process was successful.

Docker Features

The docker command is used with options and subcommands with additional arguments. Let's look at the schematic syntax:

docker [options] [command] [arguments]

You can view the table of all teams using the command:

$ docker

The table will open:

  1. attach Attach local standard input, output, and error streams to a running container
  2. build Create an image from a Docker file
  3. commit Create a new image from the container changes
  4. cp Copy files/folders between the container and local file system
  5. create Create a new container
  6. diff Check changes of files or directories in the container file system
  7. events Get real-time events from the server
  8. exec Execute the command in the running container
  9. export Export the container file system as a tar-archive
  10. history Show the history of the image
  11. images List of images
  12. import Import the contents from the tar archive to create an image of the file system
  13. info Displaying system-wide information
  14. inspect Return low-level information about objects
  15. docker kill Kill one or more running containers
  16. load Download the image from the tar archive or STDIN
  17. login Logging in to the registry
  18. docker logout Exiting the registry
  19. docker logs Get container logs
  20. pause Suspend all processes in one or more containers
  21. port List of port mappings or a specific mapping for a container
  22. ps Output the list of containers

Working with Docker images

It is not possible to use the container without the downloaded Docker Image. If no changes have been made, the utility takes the image from the official hub. It is called Docker Hub. It contains all the images that are supported by the developers of the utility. Everyone can place images in the Hub registry. Therefore, popular applications, Linux distributions, and applets already have prepared images in the repository.

Let's enter a command to check if Docker Image can be loaded into the machine's internal memory:

$ docker run hello-world

First, the utility will check if the specified image is in memory. Since Docker will not detect anything, it will download the required image and then run it in the container:


Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

9bb5a5d4561a: Pull complete


Status: Downloaded newer image for hello-world:latest

Hello from Docker!

This message shows that your installation appears to be working correctly.


This message indicates that the process of downloading and starting the desired image works without errors.

To find the desired Docker Image in the Hub, use the search subcommand and the name of the desired image. The script will start searching the content of the Docker Hub, showing all the results that match the given parameters. Pay attention to the OFFICIAL column. If there is an OK line next to the image in this column, it means you are facing an official image from the founding team and not a fork.

To download it, just type the pull subcommand. Let's assume this is an Ubuntu image. In this case we type:

$ docker pull ubuntu

This conclusion indicates that the process was successful:

$ Output

Using default tag: latest

latest: Pulling from library/ubuntu

6b98dfc16071: Pull complete

4001a1209541: Pull complete

6319fc68c576: Pull complete

b24603670dc3Pull complete

97f170c87c6f: Pull complete

Digest: sha256:5f4bdc3467537cbbe563e80db2c3ec95d548a9145d64453b06939c4592d67b6d

Status: Downloaded newer image for ubuntu:latest

The table with the installed images can be viewed with the command:

 $ docker images

Running a container command shell

The RUN command is used to start the container. Let's take a look at the options that can be used with RUN:

  • -d - starts the container in the background;
  • -t - tty's connection to the container for input and output;
  • -e - sets environment variables to accept the license agreement and change the initial configuration;
  • -name - assigning a name to the container;
  • -p - publishes container ports on the host to allow remote access to DSE, OpsCenter and Studio;
  • -i - interactive access to the command processor of the container
  • -v - bind the directory on the local host to that DSE for configuration management or saving data;
  • --link - link of DSE container to OpsCenter, Studio to DSE.

Use the command:

$ docker run -it ubuntu

We run the Ubuntu image with access to the command processor in interactive mode. After that we go to the container environment, the console will display its ID. We will need this information later when we need to specify the container to uninstall.

All the usual commands are available inside the container. Considering that the image does not contain most of the files you need. Therefore, you will need to update the repository:

$ apt-get update

Note that the sudo command is not used. Since the work is done as a user with superuser rights, there is no need to type the sudo command. Let's install a simple Dialog utility:

$ apt-get install -y dialog

Saving parameters

Any action is available inside the container, you can create files, install applications, or delete data – all actions will be relevant to the running container. When the container is deleted, all changes will also disappear. If you want to keep the settings, use the commit command. This will create a modified container. To get started we need a list of running containers:

$ docker ps

Here we need an identifier, run this command:

$ docker commit -m "what changes were added" -a "author name" container_id repository/new image name

When the process is finished, the modified container will be saved in memory. To find it, let's run the image list:

$ docker commit -m "what changes were added" -a "author name" container_id repository/new image name

Commands of running containers

Let's take a look at the list of commands to control:

  • start – starts the container that was stopped;
  • stop is the opposite value, stopping a container that is running;
  • rm – deleting a container.

You don't have to specify an identifier for the command to work correctly. You can use the name of the container, it is available in a separate column


$ docker start d9b100f2f636
$ docker start sharp_volhard

Managing Docker containers

The container list command allows you to run options:

  • -a. Displays a list of all containers available locally.
  • -l. Outputs the last created container.

Summing up

Docker is the main utility for starting and managing containers. It is easy enough to learn, a novice user can easily understand all the features. Docker significantly speeds up development, makes it easier to move the system from one server to another, and allows you to work in a secure environment.

Related Articles