In the first part, I presented the fundamental ideas behind Docker containers and how exactly they work. In this second part, we will proceed with the installation of Docker and its management as a service in our system. We will prepare our system so that in the next part we can create a personal notepad using the WordPress content management system (CMS) or the Dokuwiki which is a wiki software that doesn’t require a database.
As we discussed in the first part, to accomplish the above tasks, we would have to either manually install and configure a physical machine with the Apache, MySQL, PHP parts that are needed in order to run the WordPress CMS or the Docuwiki, or install a Linux server distribution in a virtual machine and then install and configure Apache, MySQL, PHP.
With the docker containers, we don’t have to do all the manual labor. We just need to download the prebuilt image and run it in a container that has all the stuff that we need, pre-configured for us and ready to be ran. But let’s just focus on our system preparation first.
Before we start, we need to prepare our physical machine with some prerequisites for the docker service. I will describe the procedure for the Ubuntu Linux operating system, but the same applies to any distribution really, with only slight changes in the package installation commands. Currently, Docker is supported on Ubuntu 15.10/14.04/12.04. For other distributions, you can check the official documentation (https://docs.docker.com/engine/installation/linux/).
Docker requires a 64-bit installation regardless of your Ubuntu version. Additionally, your kernel must be on 3.10 version at minimum, because Linux kernels older than 3.10 lack some of the features required to run Docker containers. These older versions are known to have bugs which cause data loss and frequently panic under certain conditions.
Installing Docker engine on Ubuntu 15.10
We will install the Docker engine from the official repositories because they regularly release new versions with new features and bug fixes while the Docker on the Ubuntu repositories is usually several versions older and not maintained.
If you have previously installed Docker on your Ubuntu installation from the default Ubuntu repositories, you should purge it first using the following command:
sudo apt-get –purge autoremove lxc-docker
Docker’s apt repository as of this writing it contains the Docker engine 1.10.1 version. Now let us set apt to use packages from the official repository:
1) Open a terminal window.
2) Add the corresponding gpg key for the Docker repository
sudo apt-key adv –keyserver hkp://p80.pool.sks-keyservers.net:80 –recv-keys 58118E89F3A912897C070ADBF76221572C52609D
3) Edit the /etc/apt/sources.list.d/docker.list file in your favorite editor. You can ignore if it doesn’t exist, we can safely create it.
sudo nano /etc/apt/sources.list.d/docker.list
Add the following line in the docker.list file
deb https://apt.dockerproject.org/repo ubuntu-wily main
Save and close the /etc/apt/sources.list.d/docker.list file.
4) Now that the new repository is added you should update the apt package index.
sudo apt-get update
5) First you should install the `linux-image-extra kernel` package. The Linux-image-extra package allows docker to use the aufs storage driver
sudo apt-get install linux-image-extra-$(uname -r)
6) Now you can install the docker engine
sudo apt-get install docker-engine
You can verify that apt is pulling docker engine from the official repository with the following command:
apt-cache policy docker-engine
With the above command, you will see the version of the docker, which should probably be 1.10.1+ and some entries that indicate the official origin of the docker package. If the information is correct and you see links to the official Docker repositories then whenever you run sudo apt-get upgrade, your system will pull the new versions from the official repository.
Managing Docker service on Ubuntu 15.10
Now that we have our system prepared let’s discuss the management of the Docker service that runs in the background.
First things first, we should learn how to start or stop the Docker service and also how to check if it is running with the systemctl tool.
To check if the docker is running and also check some useful information about our memory, CPU, process ID and some log entries, we can run:
sudo systemctl status docker
To start the Docker service, we issue the following command:
sudo systemctl start docker
To stop the Docker service, we issue the following command:
sudo systemctl stop docker
If for any reason we do not want the Docker service to run always in the background, we can disable its startup during system boot by issuing the following command:
sudo systemctl disable docker
If we want to revert the above action we can enable the Docker service to start during system boot with the following command:
sudo systemctl enable docker
With the second part, we have concluded our preparation of the underlying operating system (Ubuntu 15.10 in our case) to be able to run the latest version of Docker engine. Also, we learned how to start, stop, check the status of the Docker service and either enable or disable its startup during the system boot.
In the next (third) part, we will start using Docker images and see how we can create containers in a practical way.