Installing Docker

Please follow 3 steps to install Docker.

  1. Update Apt Packages
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
  1. Add Docker Repository
curl -fsSL | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] bionic stable"
  1. Install Docker-ce Using Apt

We need to update packages again before we proceed with installation.

sudo apt update

The following command to just check, if installation would happen from the Docker repository or not.

apt-cache policy docker-ce

Output of above command...

 apt-cache policy docker-ce
  Installed: 5:19.03.12~3-0~ubuntu-bionic
  Candidate: 5:19.03.12~3-0~ubuntu-bionic
sudo apt install docker-ce

Above will install Docker. Let us check if the Docker service is running using sudo systemctl status docker

sudo systemctl status docker

You should see following output...

sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-08-23 04:01:41 UTC; 59s ago
 Main PID: 17240 (dockerd)
    Tasks: 8
   CGroup: /system.slice/docker.service
           └─17240 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Using Docker Command

Docker command syntax is following...

docker [option] [command] [arguments]

For help do...

docker --help

Working With Docker Images

Docker containers are built from docker images. Most of the images are hosted on docker hub. Anyone can host on Docker hub. Check out following link to know more about Docker hub...

Example- Let us run docker "hello world".

docker run hello-world

You would see following output...

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

As we above, Docker downloaded the hello-world image from Docker hub.

We can search docker images using docker search command.

Example - Let us search for MySQL Docker images.

docker search mysql

You should see following output...

docker search mysql
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   9876                [OK]
mariadb                           MariaDB is a community-developed fork of MyS…   3611                [OK]
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   721                                     [OK]

We can pull the Docker image, using docker pull command.

docker pull mysql

Let us check the images that  we have on our machine.

docker images
docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               latest              0d64f46acfd1        2 weeks ago         544MB
hello-world         latest              bf756fb1ae65        7 months ago        13.3kB

As we can see, mysql is one of  the images.