How to install Docker on Ubuntu ?

Docker as we know,is an open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.In this post, we are going to take look at how to install Docker on Ubuntu 18 LTS.

Ubuntu OS requirements: Docker CE (Community Edition) supports following 64-bit versions

  • Bionic 18.04 (LTS)
  • Artful 17.10
  • Xenial 16.04 (LTS)
  • Trusty 14.04 (LTS)

For Docker EE (Enterprise Edition) please refer Docker documentation

  1. [Optional Step] this step is required only if you have older versions of the docker, uninstall using below commands
    sudo apt-get remove docker docker-engine docker.io
Uninstall Docker
Uninstall Docker
Image — Uninstall Docker
  1. Update apt packages
    sudo apt-get update
Update Packages
Update Packages
Image — Update Packages
  1. Install following Packages
  • apt-transport-https
  • ca-certificates
  • curl
  • software-properties-common
    sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common
Install Packages
Install Packages
Image — Install Packages
  1. Setup Docker’s official GPG key
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
Setup Docker GPG Key
Setup Docker GPG Key
Image — Setup Docker GPG Key
  1. Verify key with the fingerprint
    sudo apt-key fingerprint 0EBFCD88
Verify key
Verify key
Image — Verify key
  1. Add Stable repository (this command applies only to x86_64 / amd64 platform)
    sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"
Add Stable repository
Add Stable repository
Image — Add Stable repository
  1. Install Docker CE edition
    sudo apt-get update
Run apt-get update before install
Run apt-get update before install
Image — Run apt-get update before install
  1. sudo apt-get install docker-ce
Install Docker CE
Install Docker CE
Image — Install Docker CE
  1. Verify Docker installation by running the hello-world image
    sudo docker run hello-world
Verify Docker CE installation
Verify Docker CE installation
Image — Verify Docker CE installation

Docker daemon binds to a Unix socket instead of a TCP port. By default, Unix socket is owned by the user root and other users can only access it using sudo command. Docker daemon always runs as the root user. To avoid using sudo command every time follow the below steps:

  1. Create Docker group (must have been already created if not create new)
    sudo groupadd docker
  2. Add current user to Docker group
    sudo usermod -aG docker $USER
Add current user to Docker group
Add current user to Docker group
Image — Add current user to Docker group
  1. Verify that you can run docker commands without sudo.
    docker run hello-world
Validate Docker Installation
Validate Docker Installation
Image — Validate Docker Installation

Now that we have installed Docker CE,its time to understand bit about internals of Docker as well.

Docker components

Docker uses a client-server architecture. Docker client (docker command line interface) talks to the Docker daemon, which does all the heavy lifting of building, running, and distributing our Docker containers. The Docker client and daemon can run on the same system, or there is also option to connect a Docker client to a remote Docker daemon.

Docker components
Docker components
Image — Docker components (Source — Docker)
  1. Docker Daemon: Docker daemon listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes.
  2. Docker client: Docker users interact with Docker using Docker client. When you use commands such as docker run, the client sends these commands to Docker Daemon, which carries them out. The Docker client uses the Docker API.
  3. Docker registry stores Docker images. Docker Hub and Docker Cloud are public registries that anyone can use, and Docker is configured to look for images on Docker Hub by default. There is also option to run private registry.
  4. Docker Image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization.
  5. Docker container is a runnable instance of an image. We can create, start, stop, move, or delete a container using the Docker API or CLI. We can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.
  6. Dockerfile defines the steps needed to create the image and run it.

In this post,we have learned how to install Docker on Ubuntu 18.There is much more to the Docker platform than what was covered here, but now you would have got a good idea of the different components and how to configure Docker.

For other posts about Docker,check out here..

Like this post? Don’t forget to share it!

Additional Resources:

Originally published at @upnxtblog.

Experienced IT Professional. Check out my blog at https://upnxtblog.com. Also check out my course aggregation site at https://skillmeup.xyz