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. I tested this guide on Lubuntu 14.04 LTS desktop, however these instructions described below should work on Ubuntu 14.04 desktop, Server editions too.
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 sk 4.4.5-040405-generic #201603091931 SMP Thu Mar 10 00:34:17 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.5-040405-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?
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://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
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-trusty 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
Then, install the linux-image-extra kernel package and apparmor package.
To install linux-image-extra kernel package, run the following command from Terminal. If this command didn’t work, just leave it, and run the next command.
sudo apt-get install linux-image-extra-$(uname -r)
Install Apparmor suing 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 you installed Docker, start the Docker service with command:
sudo service docker start
You’ll see the following message:
start: Job is already running: 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 your 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.11.0 API version: 1.23 Go version: go1.5.4 Git commit: 4dc5990 Built: Wed Apr 13 18:34:23 2016 OS/Arch: linux/amd64 Server: Version: 1.11.0 API version: 1.23 Go version: go1.5.4 Git commit: 4dc5990 Built: Wed Apr 13 18:34:23 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.