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.
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.
Run the following command from the Terminal as root user to download Docker Compose binary file:
curl -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Then, apply executable permissions to the binary using command:
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.
On Arch Linux and its derivatives, run the following command to install pip:
sudo pacman -S python-pip
On Debian, Ubuntu, Linux Mint:
sudo apt-get install python-pip
On RHEL, Fedora, CentOS:
sudo yum install python-pip
sudo dnf install python-pip
sudo zypper install python-pip
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:
You will see an output something like below.
docker-compose version 1.11.2
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 it.
That’s all for now. I hope this helps. If you find this guide useful, please share it on your social networks and support OSTechNix.
Thanks for stopping by!
How can I benefit from this blog:
- Subscribe to our Email Newsletter : Sign Up Now
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!