Install Docker on Ubuntu

This brief tutorial aims to teach you how to install Docker on Ubuntu. To do a "clean" installation of Docker on your machine, the ideal is to ensure that you don't have any old versions installed.

Removing old versions

Therefore, we will remove the following packages:

sudo apt-get remove docker docker-engine docker.io containerd runc

Now that you are sure that no trace of the old installation remains, you can start configuring the official Docker repository.

Configuring the official repository

The first step is to install some dependencies to be able to access this repository using HTTPS.

sudo apt-get update

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

And add the official Docker GPG key:

 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Finally add the repository:

sudo add-apt-repository \
   "deb [arch = amd64] https://download.docker.com/linux/ubuntu \
   $ (lsb_release -cs) \
   stable "

Note that the command lsb_release returns the name of your Ubuntu distribution. In addition, we are defining the architecture as amd64. If your computer has a different architecture, visit the official Docker page for more details.

Installing Docker

After adding the repository you need to update your apt index:

sudo apt-get update

And finally, install the Docker packages:

sudo apt-get install docker-ce docker-ce-cli containerd.io

If everything went well, you can perform this test:

sudo docker run hello-world

This command (which requires sudo permission), downloads a simple hello-world image from Docker.

Adding your user to the Docker group

In order for you to be able to run Docker commands without using sudo, you must add a docker group:

sudo groupadd docker

And add your user to that group, like this:

sudo usermod -aG docker $ USER

Removing the installation

If you no longer wish to use Docker, you can remove it from your computer as follows:

sudo apt-get purge docker-ce docker-ce-cli containerd.io

And remove the directory it creates to store images, containers, volumes and settings like this:

sudo rm -rf /var/lib/docker

For more information visit the official Docker page. Once Docker is installed, you can also use Docker Compose. See what it is and how to install it in next post.

results matching ""

    No results matching ""