How to Install Docker in Ubuntu 18.04 LTS Server
A brief introduction To Docker
As you probably know, Docker is a fast, lightweight, OS level virtualization technology for developers and system administrators who wants to build an application with all of its dependencies, and ship it all out as only one package. Unlike other Virtualization methods, such as VMWare, Xen and VirtualBox, there is no need of separate guest operating system for each virtual machine. All Docker containers efficiently share the same Operating System Kernel. Each container will run in an isolated userspace in the same operating system.
Also, Docker containers will run on regardless of Linux operating systems. Let us say you’re working in Fedora, and I am using Ubuntu. We can still develop, share and distribute the Docker images with each other. You don’t have to worry about the OS, software, customized settings, or anything. We can continue the development as long as we have Docker installed in our host system. Simply put, it will work everywhere.
You read two terms in the above paragraphs namely Docker images and Docker containers. You might wonder, what are they? and what is the difference between them? In layman’s terms, a Docker image is a file which describes how a Container should behave, whereas Docker container is the running (or stopped) state of the Docker image. Hope you got a basic idea about Docker. Refer official Docker user guide for more details. The link is attached at the end of this guide.
Now let us go ahead and see how to install Docker in Ubuntu 18.04 LTS server edition.
To install and configure Docker, your system must meet the following minimum requirements.
- 64 bit Linux or Windows operating systems ;
- If you’re on Linux, the Kernel version should be 3.10 or above.
- Your system should be connected with Internet.
In Linux, to verify the Kernel and architecture details, run the following command from the Terminal:
$ uname -a
Linux ubuntuserver 4.15.0-48-generic #51-Ubuntu SMP Wed Apr 3 08:28:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
As you see in the above output, my Ubuntu system’s kernel version is 4.15.0-48-generic and my Ubuntu system’s architecture is 64 bit (x86_64 x86_64 x86_64 GNU/Linux). Check the bold letters in the above result.
Well, the Kernel version is higher than the minimum requirement, and the arch is 64 bit. So, we can install and use Docker without any problems. Please note that it doesn’t matter which Ubuntu OS you use. Also, It doesn’t matter whether you use Ubuntu Desktop or Ubuntu Server edition or any other Ubuntu variants such as Lubuntu, Kubuntu, Xubuntu, Docker will work just fine as long as you have the Kernel version 3.10+, and your system’s arch is 64 bit.
Install Docker in Ubuntu 18.04 LTS
First of all, update your Ubuntu system. To do so, open your Terminal, and run the following commands one by one:
$ sudo apt-get update
$ sudo apt-get upgrade
Docker is not available in the official Ubuntu repositories. So we will add the Docker repository to get the latest version of Docker.
First install the necessary certificates and to allow apt package manager to use a repository over HTTPS using command:
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Next, add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify whether the key has been added with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint:
$ sudo apt-key fingerprint 0EBFCD8
You should see an output like below.
pub rsa4096 2017-02-22 [SCEA] 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 uid [ unknown] Docker Release (CE deb) <[email protected]> sub rsa4096 2017-02-22 [S]
Add the Docker official repository:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Finally, run the following command to install latest Docker CE in Ubuntu 18.04 LTS server:
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
You can, of course, install a specific Docker version as well. To check the list of available Docker versions, run:
$ apt-cache madison docker-ce
docker-ce | 5:18.09.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.2~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.1~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 5:18.09.0~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.3~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.2~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.06.0~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages docker-ce | 18.03.1~ce~3-0~ubuntu | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
You can pick any available version from the above list and install it. For instance, to install version 5:18.09.2~3-0~ubuntu-bionic, run:
$ sudo apt install docker-ce=5:18.09.2~3-0~ubuntu-bionic docker-ce-cli=5:18.09.2~3-0~ubuntu-bionic containerd.io
Once it is installed, verify if the Docker service is started with command:
$ sudo systemctl status docker
You’ll see an output something like below.
● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2019-05-01 13:42:25 UTC; 20min ago Docs: https://docs.docker.com Main PID: 3552 (dockerd) Tasks: 10 CGroup: /system.slice/docker.service └─3552 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock May 01 13:42:20 ubuntuserver dockerd: time="2019-05-01T13:42:20.954898238Z" level=warni May 01 13:42:20 ubuntuserver dockerd: time="2019-05-01T13:42:20.955475744Z" level=warni May 01 13:42:20 ubuntuserver dockerd: time="2019-05-01T13:42:20.961574055Z" level=info May 01 13:42:22 ubuntuserver dockerd: time="2019-05-01T13:42:22.509588048Z" level=info May 01 13:42:23 ubuntuserver dockerd: time="2019-05-01T13:42:23.232441469Z" level=info May 01 13:42:24 ubuntuserver dockerd: time="2019-05-01T13:42:24.297761573Z" level=info May 01 13:42:24 ubuntuserver dockerd: time="2019-05-01T13:42:24.299299845Z" level=info May 01 13:42:25 ubuntuserver systemd: Started Docker Application Container Engine. May 01 13:42:25 ubuntuserver dockerd: time="2019-05-01T13:42:25.176174769Z" level=info May 01 13:43:59 ubuntuserver dockerd: time="2019-05-01T13:43:59.228707452Z" level=info
Great! Docker service is up and running!
If it not started already, run the following command to start it.
$ sudo systemctl start docker
To check the Docker version, run:
$ sudo docker version
Client: Version: 18.09.5 API version: 1.39 Go version: go1.10.8 Git commit: e8ff056 Built: Thu Apr 11 04:43:57 2019 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 18.09.5 API version: 1.39 (minimum version 1.12) Go version: go1.10.8 Git commit: e8ff056 Built: Thu Apr 11 04:10:53 2019 OS/Arch: linux/amd64 Experimental: false
Let us go ahead, and test whether Docker is working or not.
To do so, run:
$ sudo docker run hello-world
The above command will download a test Docker image, and execute a sample hello_world program inside the container.
If you see an output something like below, congratulations! Docker is working fine in our Ubuntu system.
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
That’s all for now. Docker is ready to use.
Install Docker Compose
Docker Compose is a tool that can be used to define and run multi-container Docker applications. With Compose, you use a Compose file to configure your application’s services. Then, using a single command, you can create and start all the services from your configuration.
We can install Docker Compose using any one of the following methods.
Download the latest Docker Compose from here.
As of writing this, the latest version was 1.24.0.
Run the following command to download latest stable Docker compose file:
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Finally, apply executable permissions to the binary using command:
$ sudo chmod +x /usr/local/bin/docker-compose
Alternatively, we can install Docker Compose using PIP. Pip is a python package manager used to install applications written in Python programming language.
Refer the following guide to install Pip on your system.
Once pip installed, run the following command to install docker compose. The following command is same for all Linux distributions!
$ pip install docker-compose
After installing Docker Compose, you can check the version with command:
$ docker-compose --version
You will see an output something like below.
docker-compose version 1.24.0, build 0aa59064
Congratulations! We have successfully installed Docker Community Edition and Docker Compose.
I installed Docker, now what? Check the next article in this series to learn the Docker basics.
To install Docker in RPM based systems such as RHEL, Fedora, CentOS, Scientific Linux and openSUSE, check the following link.
Also, download and use the following Docker Ebooks to get to know more about Docker.
And, that’s all for now. I hope this helps. If you find this guide useful, please share it on your social, professional networks and support OSTechNix.
More good stuffs to come. Stay tuned!