Install Docker on Ubuntu 18.04

Install Docker on Ubuntu 18.04

Docker is a set of the platform as a service (PaaS) products that deliver software packages called containers. Docker’s containerization technology allows you to build, test, and deploy any applications quickly. The applications build and deployed through Docker can run as portable and self-sufficient containers anywhere. Docker has become one of the best tools for container deployment. In the market, there are both free and premium tiers for this service. Docker Engine is the software that hosts the containers. These containers are isolated from one another, and it has its software, libraries, and configuration files. The containers can communicate with each other through well-defined channels.

 

Prerequisites

Before installing Docker on your Ubuntu server, make sure you are logged in as a user with sudo privileges.

 

Installing Docker on Ubuntu

The official Ubuntu 18.04 repository has the Docker installation package available, but it may not be the latest version. So, it is recommended to install the latest version of the Docker package from the Docker’s repository. Follow the below steps to install Docker on Ubuntu from the latest Docker’s repository.

1) First, update and upgrade the apt package manager index by using the following commands.

$ sudo apt update

$ sudo apt upgrade

2) Install the prerequisite packages necessary to add a new repository over HTTPS.

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

3) Next, import the repository’s GPG key by running the following.

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

4) After importing the key, add the Docker apt repository to your Ubuntu system by running the following command.

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

5) After adding the Docker apt repository, run the following command to update the apt package manager index again.

$ sudo apt update

6) After enabling the Docker repository on your system, you need to install the community version of Docker by using the following command.

$ sudo apt install docker-ce

To install a specific Docker CE version, list all the available versions in the Docker repository first by using the following command.

$ sudo apt list -a docker-ce

This command lists all the available versions in the Docker repository. Suppose if you want to install version 18.09.5 from the above lists, you need to run the following command.

$ sudo apt install docker-ce=5:18.09.5~3-0~ubuntu-bionic

If you don’t want the Docker package to update automatically, run the following command to mark it as held back.

$ sudo apt-mark hold docker-ce

7) After the installation, the Docker service starts automatically, and you can verify the status of Docker by running the following command.

$ sudo systemctl status docker

8) You can check the Docker version details by running the following command.

$ sudo docker -v

After the installation, now you have the Docker daemon service, and Docker command-line utility or the Docker client.

 

Executing the Docker Command Without Sudo

By default, to run Docker command, one should have administrator privileges. If you want to run the Docker commands as a non-root user without prepending ‘sudo’, then add the user to the Docker group. The Docker group gets created during the Docker CE package installation, and to add the user to the Docker group, you need to run the following command.

$ sudo usermod -aG docker $<USER>

In the above command, <USER> is an environment variable that holds the username of whom you want to add to the Docker group.

After updating the username in the Docker group, log out of the server and log in as the user added in the Docker group.

$ su – $<USER>

Enter the password when prompted to continue. You can confirm the addition of the logged-in user to the Docker group by running the following command.

$ id -nG

Output:

<USER> sudo docker

To add another user that you are not logged in as to the Docker group, run the following command.

$ sudo usermod -aG docker <username>

 

Use the Docker Command Without Sudo

The basic syntax of Docker command is the one shown below:

$ docker [option] [subcommand] [arguments]

To list all the available subcommands of Docker, run the following command.

$ docker

If you want help for any Docker subcommand, run the following command.

$ docker <docker-subcommand> –help

To view the system-wide information of Docker, you can run the following command.

$ docker info

To verify if the installation of Docker is proper and if it can run docker commands without prepending sudo, run the following command.

S docker container run hello-world

This above command checks the hello-world image locally first, and if it could not find this image locally, it downloads the image from Docker Hub, the default repository for Docker. After the download, the Docker creates a container from the image. Then, the application within the container gets executed to display the message within the image.

You can search for images available on the Docker Hub by running the Docker command with search as the subcommand.

If you want to search for the Ubuntu images, then run the following command.

$ docker search ubuntu

After listing the available images, if you want to download all these images to your local system, run the following pull command.

$ docker pull ubuntu

To list the images on your system, run the following command.

$ docker images

 

Upgrading Docker Version

When a new Docker version is released, and you want to update the Docker to the latest version, run the following commands with sudo privilege.

$ sudo apt update

$ sudo apt upgrade

 

If you need any further help, please do reach our support department.

Leave a Reply