Install Docker on Ubuntu 18.04

Docker is an OS-level virtualization solution built around Linux kernel features like namespaces and cgroups to provide isolation for software packages called containers.

Prerequisites:

  • You need access to a Linux server, with sudo or root privileges.

Installation:

Before installing the Docker package, we will ensure the package cache is up to date.

$sudo apt-get update

We will then install some needed dependencies.

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

Next up, we need to import the gpg public key for the Docker CE repository

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

Now that the gpg public key has been added, we can then add the Docker CE repository.

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

Install the Docker-CE package.

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

Configuration:

First, we must configure a user if we want to run docker without root privileges.  I have created a user called test_user.  The following command will add the user “test_user” to the docker group.

$sudo usermod -a -G docker test_user

In order for the changes to be recognized, you must log out and back into your existing shell session or use the following command.

$su test_user

Verification:

We can use systemctl to ensure the docker service is started and set to enabled at boot.

$sudo systemctl status docker.service

Check which docker version is installed.

 $docker --version

Run a test container. If this completes successfully, then you have successfully configured the docker service.

$docker run hello-world

Conclusion

In this article, you learned how to install, configure, and verify the docker service on Ubuntu 18.04.  Check out the official docker documentation for more information.

Leave a Reply

Your email address will not be published. Required fields are marked *