How to Install Docker in Ubuntu
Docker – A brief introduction
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, 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 heard two terms in the above paragraphs, Docker images, and Docker containers. You might ask what are they? 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.
In this tutorial, let us see how to install Docker in Ubuntu in Ubuntu 16.04 LTS server.
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:
Linux ubuntuserver 4.4.0-57-generic #78-Ubuntu SMP Fri Dec 9 23:50:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
As you see in the above output, my Ubuntu system’s kernel version is 4.4.0-57-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. Clear?
Install Docker in Ubuntu 16.04
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 using command:
sudo apt-get install apt-transport-https ca-certificates
Add the GPG key:
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Next, install recommended prerequisites:
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
Create a new file /etc/apt/sources.list.d/docker.list as shown below.
sudo nano /etc/apt/sources.list.d/docker.list
Add the following lines:
deb https://apt.dockerproject.org/repo ubuntu-xenial main
Save the file by pressing CTRL+O and press Enter, and then CTRL+X to close the file.
Now, update the repository lists using command:
sudo apt-get update
Remove any older versions if any exists using the following command:
sudo apt-get purge lxc-docker
Install Apparmor using command:
sudo apt-get install apparmor
Finally, install Docker using command:
sudo apt-get install docker-engine
Type ‘Y’ and press ENTER when it ask you to continue.
Once installed, check whether the Docker service is started or not using 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: e Active: active (running) since Tue 2017-01-03 14:05:22 IST; 28s ago Docs: https://docs.docker.com Main PID: 8833 (dockerd) CGroup: /system.slice/docker.service ├─8833 /usr/bin/dockerd -H fd:// └─8838 docker-containerd -l unix:///var/run/docker/libcontainerd/dock
If it not started already, run the following command to start it.
sudo systemctl start docker
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.
Hello from Docker. This message shows that your installation appears to be working correctly.
To check the Docker version, run:
sudo docker version
Client: Version: 1.12.5 API version: 1.24 Go version: go1.6.4 Git commit: 7392c3b Built: Fri Dec 16 02:42:17 2016 OS/Arch: linux/amd64 Server: Version: 1.12.5 API version: 1.24 Go version: go1.6.4 Git commit: 7392c3b Built: Fri Dec 16 02:42:17 2016 OS/Arch: linux/amd64
That’s all for now. Docker is ready to use.
I installed Docker, now what? Check the next article in this series to learn the Docker basics.
To install Docker in other Linux versions, check the official docs in the following link.