Starting with docker

Today, we will see Docker, the “open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.”

Docker is a container-based software framework for automating deployment of applications. “Containers” are encapsulated, lightweight, and portable application modules. When using docker, your application is packaged in containers, and you just have to run this container to starting-up your application.

Linux release

For this post, I will use a fresh CentOS 6.9 release.

Adding the “Extra Packages for Enterprise Linux” repository

Actually, Docker is part of “Extra Packages for Enterprise Linux”, called “EPEL”, which is a community repository. This repository contains non-standard packages for Red Hat distributions.

To add it, just execute the following command line :

rpm -iUvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

When added, as best practice, we will update linux packages by using the following command line :

yum update -y

Now, you are able to install Docker !

Installing Docker

Docker is part of the “docker-io”. To install Docker, just install the “docker-io” package !

yum -y install docker-io

Once the installation completes, just start docker :

service docker start

To be sure that Docker will start when the server boots, configure it :

chkconfig docker on

Ok, you just installed docker ! Be ready to play with it !

What to do with Docker ?

You can use https://hub.docker.com/ to explorer community packages, adding it to your Docker installation and running them on your system ! You will be able to deploy some mysql, apache or gitlab instances within seconds !

Example : Deploying GitLab

GitLab is a powerfull development tool allowing you to monitor and manage your project lifecycle. I just start retrieving the GitLab image from https://hub.docker.com/r/gitlab/gitlab-ce/.

The pull command

The pull command will fetch the image from an external repository, and adding it to your Docker instance ! On your server, just run the pull command to retrieve gitlab-ce and enabling it on your system :

docker pull gitlab/gitlab-ce

The run command

When the image is successfully extracted, run it using this simple command :

docker run --detach \
    --hostname host.name \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

This command will :

  • mount /srv/gitlab/config (server directory) to /etc/gitlab (container directory),
  • mount /srv/gitlab/logs (server directory) to /var/log/gitlab (container directory),
  • mount /srv/gitlab/data (server directory) to /var/opt/gitlab (container directory),
  • deploy gitlab on port 80, 443 and 22,
  • name the container “gitlab”

It’s always usefull to store configuration, log and data on server side, for backing them up and changing server if needed.

Ok, but I already have a service listening on port 80. What to handle this ?

Likely, you will not run only one container on your server, so Docker is able to do some port forwarding between your server and the container. You can use the “–publish” line argument to do this :

docker run --detach \
    --hostname host.name \
    --publish 9443:443 --publish 9080:80 --publish 9022:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest

With this command, I will deploy my GitLab instance on port 9080, 9443 and 9022 ! Adding an httpd component in front of Docker allowing me to redirect all request on port 80 to port 9080 if my dns is associated with gitlab !

You will find more informations on https://docs.gitlab.com/omnibus/docker/, the official gitlab documentation for Docker image !

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.