Docker is a free and open source project for the automation of deployment of apps under software containers that provides an open platform to pack, ship and run any application any where. It makes an awesome use of the resource isolation features of the linux kernel such as cgroups, kernel namespaces, and union-capable file system. It is pretty easy and simple for deploying and scaling web apps, databases and back-end services independent on a particular stack or provider. The latest release ie version 1.11.1 consists of many additional features and bug fixes. In this article, we'll be installing the latest Docker Engine 1.11.1 in a machine running Ubuntu 16.04 LTS "Xenial" .
Following are the system requirements that are essential to run the latest Docker Engine in Ubuntu 16.04 LTS Xenial.
- It currently requires 64 bit version of host to run so, we'll require a 64 bit version of Ubuntu Xenial installed on the host.
- As we require to download images of containers frequently, we'll require a good internet connectivity in the host.
- Make sure that the machine's CPU supports virtualization technology and virtualization support is enabled in BIOS.
- Ubuntu Xenial running Linux kernel version 3.8 and above are supported.
Updating and Upgrading Xenial
First of all, we'll need to update the local repository index of the Ubuntu repositories from the nearest mirror service so that we have the index of all the latest packages available on the repository through internet. To do so, we'll need to run the following command in a terminal or console.
$ sudo apt-get update
As our local repository index has been updated, we'll upgrade our Ubuntu Xenial to the latest packages available in the repositories via apt-get package manager.
$ sudo apt-get upgrade
Installing Docker Engine
Once our system has been upgraded, we'll move towards the installation of the latest Docker Engine ie version 1.11 in our machine running the latest and greatest Ubuntu 16.04 Xenial LTS. We have many ways to install it in Ubuntu, either we run a simple script written by the official developers or we manually add the Docker's official repository and install it. Here, in this tutorial, we'll show both methods to install Docker Engine.
1. Adding the Repository
First of all, we'll need to add the new GPG key for our docker repository.
$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
As the new GPG key for docker repository has been added to our machine, we'll now need to add the repository source to our apt source list. To do so, we'll use a text editor and create a file named docker.list under /etc/apt/sources.list.d/ directory.
$ sudo nano /etc/apt/sources.list.d/docker.list
Then, we'll gonna add the following of line into that file in order to add the repository to the apt's source..
deb https://apt.dockerproject.org/repo ubuntu-xenial main
2. Updating the APT's Index
As our repository for docker has been addded, we'll now gonna update the local repository index of APT package manager so that we can use it to install the latest release. In order to update the local repository index, we'll need to run the following command inside a terminal or console.
$ sudo apt-get update
3. Installing Linux Kernel Extras
Now, as its recommended, we'll gonna install the Linux Kernel Extras in our machine running Ubuntu Xenial. We'll need to install this package as its important for us to enable the use of aufs storage driver. So, to install the linux-image-extras kernel package in our machine, we'll need to run the following command.
$ sudo apt-get install linux-image-extra-$(uname -r)
Here, as we have linux kernel 4.4.0-22 installed and running, the linux kernel extras of the respective kernel will be installed.
4. Installing Docker Engine
Once everything is setup and done, we'll now go towards the main part of the work where we'll install the latest docker engine in our latest Ubuntu 16.04 LTS Xenial machine. To do so, we'll need to run the following simple apt-get command.
$ sudo apt-get install docker-engine
Finally, we are done installing Docker Engine, once we are done the installation process, we'll now move towards the next step where we'll add our current running user to the docker group.
If we wanna automate everything done above in the Manual installation method, we'll need to follow the this step. As said above, Docker developers have written an awesome script that will install docker engine in our machine running Ubuntu 16.04 LTS Xenial fully automated. This method is pretty fast, easy and simple to perform. A person with little knowledge of Ubuntu 16.04 can easily install docker using this script. So, before we start, we'll need to make sure that wget is installed in our machine. To install wget downloader, we'll need to run the following command.
$ sudo apt-get install wget
Once get downloader is installed in our machine, we'll need to run the following wget command in order to run the docker's official script to install the latest Docker Engine.
$ wget -qO- https://get.docker.com/ | sh
Adding User to Docker Group
Now, we'll gonna add our users to the docker group, doing so will allow docker daemon to provide permissions to the users under group docker to have authentication to run and manage the docker containers.
$ sudo usermod -aG docker arun
Once done, we'll need to logout and again login to the system to apply the changes into effect.
Starting the Docker Daemon
Next, we'll gonna start our Docker Daemon so that we can run, manage and control containers, images in our Ubuntu machine. As Ubuntu 16.04 LTS Xenial runs systemd as its default init system, we'll need to run the following systemctl command to start docker daemon.
$ sudo systemctl start docker
Checking the version
As our docker daemon has been started, we'll now gonna test if its installed and running properly or not by checking the version of docker engine installed in our machine.
$ docker -v
Docker version 1.11.1, build 5604cbe
So, as version 1.11.1 was released and available during the time of writing this article, we must see the above output.
Running Docker Containers
Now, we'll gonna run our first docker container in this step. If everything above is setup and done properly as expected, we'll now be able to run a container. Here in this tutorial, we'll gonna run our all time favorite testing container called Hello World. In order to run hello-world container, we'll need to run the following docker command.
$ docker run hello-world
Now, doing this should print an output "Hello from Docker." from the container. This verifies that we have successfully installed docker engine and is capable of running container on it.
In order to check what images where pulled during running the hello-world container, we'll need to run the following docker command.
$ docker images
As our docker is running successfully, we'll also need to learn how to manage it. In this tutorial, we'll have a look into few basic docker commands which are used to stop, remove, pull a docker container and images.
Stopping a Running Container
Now, if we wanna stop a running container, we'll need to run the following command first to see the list of running containers.
$ docker ps -a
Then, we'll need to run the following docker stop command with the respective container id.
$ docker stop 646ed6509700
Removing a Container
To remove a stopped container, we'll need to run the following command specifying the stopped unused container id.
$ docker rm 646ed6509700
Pulling an Image
In order to pull a docker image, we'll need to run the pull command.
$ docker pull ubuntu
The above command pulls the latest image of ubuntu from the Docker Registry Hub.
Removing an Image
It is pretty easy to remove a docker container, first we'll need to list the available images in our machine.
$ docker images
Then, we'll run the following command to remove that image.
$ docker rmi ubuntu
We have many commands to manage it, we can see more in the official documentation of Docker.
Docker is an awesome technology enabling us to easily pack, run and ship application independent of platform. It is pretty easy to install and run the latest Docker Engine in the latest Ubuntu release ie Ubuntu 16.04 LTS Xenial. Once the installation is done, we can move further towards managing, networking and more with containers. So, if you have any questions, suggestions, feedback please write them in the comment box below. Thank you ! Enjoy :-)
You might also like
Filed Under : LINUX HOWTO