{"id":121,"date":"2018-02-04T17:40:44","date_gmt":"2018-02-04T16:40:44","guid":{"rendered":"http:\/\/blog.xoupix.fr\/?p=121"},"modified":"2018-02-04T17:57:32","modified_gmt":"2018-02-04T16:57:32","slug":"starting-with-docker","status":"publish","type":"post","link":"https:\/\/blog.xoupix.fr\/index.php\/2018\/02\/04\/starting-with-docker\/","title":{"rendered":"Starting with docker"},"content":{"rendered":"<p>Today, we will see Docker, the &#8220;open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.&#8221;<\/p>\n<p><!--more--><\/p>\n<p>Docker is a container-based software framework for automating deployment of applications. \u201cContainers\u201d 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.<\/p>\n<h1>Linux release<\/h1>\n<p>For this post, I will use a fresh CentOS 6.9 release.<\/p>\n<h1>Adding the &#8220;Extra Packages for Enterprise Linux&#8221; repository<\/h1>\n<p>Actually, Docker is part of &#8220;Extra Packages for Enterprise Linux&#8221;, called &#8220;EPEL&#8221;, which is a community repository. This repository contains non-standard packages for Red Hat distributions.<\/p>\n<p>To add it, just execute the following command line :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">rpm -iUvh http:\/\/dl.fedoraproject.org\/pub\/epel\/6\/x86_64\/epel-release-6-8.noarch.rpm<\/pre>\n<p>When added, as best practice, we will update linux packages by using the following command line :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">yum update -y<\/pre>\n<p>Now, you are able to install Docker !<\/p>\n<h1>Installing Docker<\/h1>\n<p>Docker is part of the &#8220;docker-io&#8221;. To install Docker, just install the &#8220;docker-io&#8221; package !<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">yum -y install docker-io<\/pre>\n<p>Once the installation completes, just start docker :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">service docker start<\/pre>\n<p>To be sure that Docker will start when the server boots, configure it :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">chkconfig docker on<\/pre>\n<p>Ok, you just installed docker ! Be ready to play with it !<\/p>\n<h1>What to do with Docker ?<\/h1>\n<p>You can use\u00a0https:\/\/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 !<\/p>\n<h1>Example : Deploying GitLab<\/h1>\n<p>GitLab is a powerfull development tool allowing you to monitor and manage your project lifecycle. I just start retrieving the GitLab image from\u00a0https:\/\/hub.docker.com\/r\/gitlab\/gitlab-ce\/.<\/p>\n<h2>The pull command<\/h2>\n<p>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 :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">docker pull gitlab\/gitlab-ce<\/pre>\n<h2>The run command<\/h2>\n<p>When the image is successfully extracted, run it using this simple command :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">docker run --detach \\\r\n    --hostname host.name \\\r\n    --name gitlab \\\r\n    --restart always \\\r\n    --volume \/srv\/gitlab\/config:\/etc\/gitlab \\\r\n    --volume \/srv\/gitlab\/logs:\/var\/log\/gitlab \\\r\n    --volume \/srv\/gitlab\/data:\/var\/opt\/gitlab \\\r\n    gitlab\/gitlab-ce:latest<\/pre>\n<p>This command will :<\/p>\n<ul>\n<li>mount \/srv\/gitlab\/config (server directory) to \/etc\/gitlab (container directory),<\/li>\n<li>mount \/srv\/gitlab\/logs (server directory) to \/var\/log\/gitlab (container directory),<\/li>\n<li>mount \/srv\/gitlab\/data (server directory) to \/var\/opt\/gitlab (container directory),<\/li>\n<li>deploy gitlab on port 80, 443 and 22,<\/li>\n<li>name the container &#8220;gitlab&#8221;<\/li>\n<\/ul>\n<p>It&#8217;s always usefull to store configuration, log and data on server side, for backing them up and changing server if needed.<\/p>\n<h2>Ok, but I already have a service listening on port 80. What to handle this ?<\/h2>\n<p>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 &#8220;&#8211;publish&#8221; line argument to do this :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">docker run --detach \\\r\n    --hostname host.name \\\r\n    --publish 9443:443 --publish 9080:80 --publish 9022:22 \\\r\n    --name gitlab \\\r\n    --restart always \\\r\n    --volume \/srv\/gitlab\/config:\/etc\/gitlab \\\r\n    --volume \/srv\/gitlab\/logs:\/var\/log\/gitlab \\\r\n    --volume \/srv\/gitlab\/data:\/var\/opt\/gitlab \\\r\n    gitlab\/gitlab-ce:latest<\/pre>\n<p>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 !<\/p>\n<p>You will find more informations on\u00a0https:\/\/docs.gitlab.com\/omnibus\/docker\/, the official gitlab documentation for Docker image !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, we will see Docker, the &#8220;open platform for developers and sysadmins to build, ship, and run distributed applications, whether on laptops, data center VMs, or the cloud.&#8221;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":8,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":344,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/posts\/121\/revisions\/344"}],"wp:attachment":[{"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.xoupix.fr\/index.php\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}