Docker Containers – Part 1 Installation

Containers in DevOps allows an application to run from any supported environment. An application running in a Container can run in Windows and Linux without any changes to the application. A container is a lightweight piece of software similar in nature to FreeBSD Jails or Linux Containers (LXD). However, a container isn’t like a traditional Operating System. Although Containers are configurable to behave like an OS, this is not the design. Containers are highly configurable, and are able to run just about any application. For example, middle-tier applications, web servers, and in some cases, databases. One of the more popular Containers is Docker, which is the focus of this post, but there are many more.

Docker has a few different offerings. The two most common are Community Edition (CE) and Enterprise Edition (EE). CE is the free and unsupported version whereas EE is a paid model and bundled with support.

Before installing and configuring Docker, we need to understand some key terms.

Images are templates for running a container. For example, building a middle-tier application server, an installation of JBoss, a version of Java and an Oracle driver are required to be part of an image. You can see all of the images on a system by running the docker images command.

Containers are running instances of images. To see the containers, use the command docker ps -a.

Repositories are sets of images with different tags. This is similar to code repositories where you check out different versions of code based upon a tag or version. Omitting the tag will checkout the latest image version. With repos, you can create and share the repo with the world (which is the default behavior) or you can keep the repo private.

Dockerfile is the configuration file used while creating a Docker image.

Installing Docker

Windows

Docker is easy to install no matter which OS is being used. On Windows, use this link to download the stable version of Docker. The installer works like any other – double click it and follow the instructions. Note: .Net version 4.0.3 is required for Docker.

RHEL, CENTos or Fedora Linux

Prerequisites

First, install the following required packages, and then enable the Docker  Yum repository as root or a user with yum sudo privileges.

yum install -y yum-utils device-mapper-persistent-data lvm2

Next, add the Yum Docker repo

yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo

Once these steps are complete, you can use yum to install Docker and service to start the Docker process.

yum install -y docker
service docker start

Ubuntu Linux

Install the prerequisite software, add the gpg key to the system and add the Docker repository. Adding the repository will allow us to use apt-get to install Docker.

apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Once the software is installed and the key added to the system, use apt-get to install Docker Community Edition (docker-ce).

apt-get install docker-ce

Linux

No matter which version of Linux,  only the root user is configured to run Docker commands. If other users need permissions, then create a docker group as root, and add the users into the group. The gpasswd command will add the user to the docker group. It takes the username and group as arguments.

groupadd docker
usermod -G docker dockeruser1
service docker restart

After the installation, you can now use the docker command to list images and run containers. In the next post, we will create our own repository and make it publicly available.