<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Docker Captain - Medium]]></title>
        <description><![CDATA[Let Docker take care of the environment. You focus on development - Medium]]></description>
        <link>https://medium.com/docker-captain?source=rss----1f3d08356982---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Docker Captain - Medium</title>
            <link>https://medium.com/docker-captain?source=rss----1f3d08356982---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:38:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/docker-captain" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Creating the first Docker Image and Pushing it to Docker Hub]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/docker-captain/creating-the-first-docker-image-and-pushing-it-to-docker-hub-4e02bea48e81?source=rss----1f3d08356982---4"><img src="https://cdn-images-1.medium.com/max/826/1*ttU6oMoZztKk2kjJid6PuQ.png" width="826"></a></p><p class="medium-feed-snippet">In my previous article I explained to you about what are containers, also I mentioned that Docker is a container platform. In this article&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/docker-captain/creating-the-first-docker-image-and-pushing-it-to-docker-hub-4e02bea48e81?source=rss----1f3d08356982---4">Continue reading on Docker Captain »</a></p></div>]]></description>
            <link>https://medium.com/docker-captain/creating-the-first-docker-image-and-pushing-it-to-docker-hub-4e02bea48e81?source=rss----1f3d08356982---4</link>
            <guid isPermaLink="false">https://medium.com/p/4e02bea48e81</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[docker-image]]></category>
            <dc:creator><![CDATA[Yasiru Nilan]]></dc:creator>
            <pubDate>Fri, 15 Sep 2017 06:36:25 GMT</pubDate>
            <atom:updated>2021-06-05T04:17:31.774Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Brief Introduction Containers and Docker]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/docker-captain/brief-introduction-containers-and-docker-b36ae6f25d25?source=rss----1f3d08356982---4"><img src="https://cdn-images-1.medium.com/max/1190/1*n6tmcXlocneM1nFbwwnUow.png" width="1190"></a></p><p class="medium-feed-snippet">We are living in a world where every day we got to hear about some new technologies. In the past it took several months to hear about some&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/docker-captain/brief-introduction-containers-and-docker-b36ae6f25d25?source=rss----1f3d08356982---4">Continue reading on Docker Captain »</a></p></div>]]></description>
            <link>https://medium.com/docker-captain/brief-introduction-containers-and-docker-b36ae6f25d25?source=rss----1f3d08356982---4</link>
            <guid isPermaLink="false">https://medium.com/p/b36ae6f25d25</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Yasiru Nilan]]></dc:creator>
            <pubDate>Sat, 09 Sep 2017 07:01:09 GMT</pubDate>
            <atom:updated>2021-06-05T04:16:54.407Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Dockerized PHP Development with PHPStorm]]></title>
            <link>https://medium.com/docker-captain/dockerized-php-development-with-phpstorm-f5d69fec133?source=rss----1f3d08356982---4</link>
            <guid isPermaLink="false">https://medium.com/p/f5d69fec133</guid>
            <category><![CDATA[phpstorm]]></category>
            <category><![CDATA[phpunit]]></category>
            <category><![CDATA[xdebug]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Ridwan Shariffdeen]]></dc:creator>
            <pubDate>Sat, 14 Jan 2017 18:06:47 GMT</pubDate>
            <atom:updated>2017-01-14T18:06:46.918Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yXHSUWM35ee-6iGY.jpg" /></figure><p>Debugging is the most annoying part of code development and nobody enjoys the process especially when it is not your code. In order to develop an application smoothly you need to setup the right tools correctly that help make the process a little less painful. This get even worse if you are using Docker to setup your development environment and the tools you usually need are not promptly available at the command line. In this article, I will show how to integrate docker components in PHPStorm to ease your pain.</p><h3>Docker Environment</h3><p>Docker is an eco-system for building, shipping and running applications in multiple environments, giving programmers, devOps and sysadmins the common box they need to configure in order to get their job done in their software development pipeline. You can easily setup your <a href="https://medium.com/docker-captain/setting-up-a-dev-environment-using-docker-78ad783a410a">dev environment using Docker </a>for multiple operating systems (Windows, RedHat, Ubuntu etc), multiple versions of applications (PHP 5.5, 7 etc) and multiple application services (Java, Ruby, Python etc). Having Docker to take care the environment problem we can leverage it’s benefit to focus on development.</p><p>But the problem is that most of the IDE’s are developed to run on top of the host system and very few support containerized environments. But not all hope is lost, most IDE’s are now providing integration support for Docker. I will be using PHPStorm 2016.3 to demonstrate the idea.</p><h3>PHPStorm &amp; Docker Integration</h3><p>Once you have configured Docker to deploy your development environment, we can start configuring PhpStorm to work with Docker. First we need to configure the Docker daemon with our PhpStorm, this could either be in a remote host using API or directly in your local machine socket. Go to file-&gt; settings -&gt; Build, Execution, Deployment -&gt; Docker</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gB4_zDsxHA_9jqPFx0roYQ.png" /></figure><p>Click on the + icon to add a Docker daemon and setup the correct configuration. In your local machine docker can be accessed using the unix socket, for docker-compose you can give the absolute path for the executable or leave the command name if its configured with your profile. Once you have a Docker daemon configured, the next step is to configure which image we should use to run our application for debugging or testing purposes. In your settings menu go to Languages &amp; Frameworks -&gt; PHP. Click on configure CLI interpreter,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*QydgJlG4u09RRXAMijyx-A.png" /></figure><p>Select the Docker server you configured earlier and it will list the images you currently have pulled in your machine. You can select one image from existing list or you can type the image name you want the interpreter to be on. Once you select the image PHPStorm will automatically detect the PHP version and the Debugger version in the image.</p><p>Finally, we need to configure phpunit so within the IDE itself you can execute test and do various test activities that are supported by PHPStorm. In the settings windows go to Languages &amp; Frameworks -&gt; PHP -&gt; PHPUnit and add a PHPUnit by clicking the + button and select Remote Interpreter, in the drop down you will find the interpreter we just configured, select the settings and provide the path to the phpunit program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CgE0unANm50VkMIULMLajQ.png" /></figure><p>Your docker environment should provide support for Xdebug in order to configure the development workflow properly. Using xdebug we can make our lives easier as every time we run a script in PHP, information will be sent to our IDE and it will display it in an informative view. This is a sample configuration for xdebug.ini</p><pre>xdebug.remote_enable=on<br>xdebug.remote_autostart=on<br>xdebug.remote_connect_back=off<br>xdebug.remote_handler=dbgp<br>xdebug.profiler_enable=0<br>xdebug.profiler_output_dir=&quot;/var/www/html&quot;<br>xdebug.remote_host=172.17.0.1<br>xdebug.remote_port=9000</pre><p>So assuming everything is configured inside the container, we will enable Debugging in PhpStorm as follow. Open the project via PHPStorm, we need to configure the container where our code is running. Add all containers (if multiple used) so it would be easy when we need to configure the debugging options. Go to File-&gt;settings and search for the keyword ‘servers’, you will get a screen like this;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*ZCW0KJy79wHVanU2WYyVtw.png" /><figcaption>PHPStorm Settings : Servers</figcaption></figure><p>Click on the + sign and add the containers by setting a name you prefer, and provide the IP address of the container (which you can obtain using Docker command <strong>docker inspect</strong> piped to grep using a regex for easiness) and the port its running (Apache port, Nginx port etc). You should tick the option “Use path mappings” and provide the host path and absolute path inside the container. For example your code may reside in your host machine in “/home/user/workspace/php-app” and inside the container it will be in your web server Document root, something like “/var/www/html/php-app”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*dC4XBb0gfMeZeUx2_ZCxUQ.png" /><figcaption>Configuring containers with different PHP versions</figcaption></figure><p>Everything is set for you to run your tests and debug your code using any PHP version thanks to Docker. There are many more features PHPStorm offers you to get the <a href="https://blog.jetbrains.com/phpstorm/2015/10/docker-support-in-phpstorm/">power of Docker</a>, you can even run Docker commands view Docker containers, you can even debug containers itself inside using the IDE. All in All PHPStorm is a great IDE which provides just everything you need when your developing your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5d69fec133" width="1" height="1" alt=""><hr><p><a href="https://medium.com/docker-captain/dockerized-php-development-with-phpstorm-f5d69fec133">Dockerized PHP Development with PHPStorm</a> was originally published in <a href="https://medium.com/docker-captain">Docker Captain</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting started with Docker]]></title>
            <link>https://medium.com/docker-captain/docker-basics-f1a06fde18fb?source=rss----1f3d08356982---4</link>
            <guid isPermaLink="false">https://medium.com/p/f1a06fde18fb</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-lerning]]></category>
            <category><![CDATA[docker-in-action]]></category>
            <category><![CDATA[docker-tutorial]]></category>
            <dc:creator><![CDATA[Ridwan Shariffdeen]]></dc:creator>
            <pubDate>Sat, 14 Jan 2017 14:50:13 GMT</pubDate>
            <atom:updated>2017-01-14T14:50:00.588Z</atom:updated>
            <content:encoded><![CDATA[<p>Docker is an umbrella term to introduce a set of complementary tools that works together to provide you a high level API to automate the shipping and deployment process of your application.<a href="http://containerization,%20process%20isolation,%20and%20union%20filesystems"> Docker simplifies the deployment</a> process and add meaning to devOps practices with containerization, process isolation, and union filesystems. So let’s understand the concepts of docker before we get into the implementation details.</p><h4>Docker Image</h4><p>Docker image is the basis of containers. It’s a collection of layers stacked on top of each other. Each Docker image references a list of read-only layers that represent filesystem differences. Think of it like the jar file for java applications, you create one jar file but you can deploy it anywhere a java run time is enabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*hZgRPWerZVbaGT8jJiJZVQ.jpeg" /><figcaption>structure of an docker image</figcaption></figure><p>We can create our own docker images, but you will be able to find the exact same image you wanted to create if you just checked at <a href="https://hub.docker.com/">Docker Hub</a>. Docker tools to manage images, provide a easy way to build, ship and deploy. Just build your own image, push to docker hub and everyone can pull the image to deploy a container.</p><p>Furthermore, docker images are extensible. Yes that’s right! you can even extend one of the official docker-image which will have the same attributes of your selected image but with additional settings you put on it. The advantage is reuse of open source code. You don’t have to re-invent the same Docker Image but rather extend an existing image.</p><h4>Docker Container</h4><p>Docker container is the actual running piece created from a docker image. The only difference between a docker image and a docker container is a top writable layer. When you create a new container, you add a new, thin, writable layer on top of the underlying stack. This layer is often called the “container layer”. All changes made to the running container — such as writing new files, modifying existing files, and deleting files — are written to this thin writable container layer. But once you delete the container, this top layer will be deleted as well. So it’s not persistent. The best thing with docker is that you can create a docker image using the current docker container with a commit. Hence, enabling us to capture system information and make it immutable so its reproducible anywhere. This solves many of the server related problems we encounter these days.</p><h4>Dockerfile</h4><p>Blueprint of a docker image (a text document) is known as Dockerfile. This file contains all the commands you would run in order to build the docker image you want. Docker can build images reading this file, which is one of the key advantages of docker.</p><pre>#<br># Super simple example of a Dockerfile<br>#<br>FROM ubuntu:latest<br>MAINTAINER Andrew Odewahn &quot;odewahn@oreilly.com&quot;<br><br>RUN apt-get update<br>RUN apt-get install -y python python-pip wget<br>RUN pip install Flask<br><br>ADD hello.py /home/hello.py<br><br>WORKDIR /home</pre><p>So putting everything we discussed so far, we first write a Dockerfile which is like the definition of the image. Using the Dockerfile we create a docker image. We then push this image to Docker Hub and provide a unique tag that can be used to identify our image. Using this tag and image name, we can pull the docker image and deploy on another computer as a docker container.</p><h3>Docker in Action</h3><p>Docker has so many new concepts and words after sometime you get a headache understanding one another. So lets take a break from the theoretical learning and run some commands and get a feeling of what docker can offer. First and foremost you need to install docker in your machine. You can find clear and precise instructions at their website on how to install docker, depending on your operating system. If you are on windows or Mac, <a href="https://www.docker.com/products/docker-toolbox">download the docker toolbox</a> and follow the wizard, everything will be setup for you. If your having a linux operating system there is a easy way to install docker, using curl or wget.</p><pre> curl -sSL <a href="https://get.docker.com/">https://get.docker.com/</a> | sh</pre><p>or</p><pre>wget -qO- <a href="https://test.docker.com/">https://test.docker.com/</a> | sh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*vT--WWdeoNt5bDz_3HU3aQ.jpeg" /><figcaption>make sure you follow the instructions properly for your operating system</figcaption></figure><p>Assuming you have installed docker properly, let’s continue to run some commands. To check if you have docker installed, run</p><pre>docker version</pre><p>you should be able to see a output similar to this</p><pre>Client:<br> Version:      1.11.1<br> API version:  1.23<br> Go version:   go1.5.4<br> Git commit:   5604cbe<br> Built:        Tue Apr 26 23:30:23 2016<br> OS/Arch:      linux/amd64</pre><pre>Server:<br> Version:      1.11.1<br> API version:  1.23<br> Go version:   go1.5.4<br> Git commit:   5604cbe<br> Built:        Tue Apr 26 23:30:23 2016<br> OS/Arch:      linux/amd64</pre><p>which means you have docker installed in your machine. Lets check what are the running containers in your machine by issuing the following command</p><pre>docker ps</pre><p>PS: If the current user is not on the docker group, you will be getting an error like, “docker daemon is not running”. In that case you can add your current user to docker group using</p><pre>sudo usermod -aG docker $your_user</pre><p>If everything is working fine, you should be able to see a list of containers running. But if your a beginner, it would be empty. So let’s try running a ubuntu container with just a hello world example.</p><pre>docker run ubuntu echo &quot;hello-world&quot;</pre><p>This command entails several other docker commands to serve your desire. The above command says “docker please run a ubuntu container and print hello world”. Before I explain how docker would take care of the rest, let me first briefly explain about docker image name and tag. Basically each docker image has it’s own image name and a tag that uniquely identifies a docker image. For example we have several nginx containers like nginx:alpine, nginx:latest etc. If you have not mentioned a tag by default docker would assume the tag is ‘latest’. So when we request a ubuntu container it would run a ubuntu:latest container.</p><p>So now that’s clear, lets see how docker do the necessary to run our command. First docker would check in your local repository if there is a docker image names ubuntu:latest. If there is no such image it would pull the image from Docker Hub or any pre-configured private/public registry. You can confirm this by issuing the following command and observing the images you have in your local machine, once you run the above command.</p><pre>docker images</pre><p>Once the image is pulled, docker would create a container and then run the echo command. This would print “hello-world” and exit. Amazing right? You just spin up a ubuntu environment and printed ‘hello world’ in a matter of few seconds. Docker containers are more useful for short-time, small-scale jobs. You can just run the particular command once and get rid of the container.</p><p>You can run a container in daemon mode (in background) by indicating at the docker run command. So, let’s try running a Apache container in daemon mode.</p><pre>docker run -d nginx</pre><p>This would fetch the ‘latest’ nginx image and initialize a docker container in daemon mode. In order to access the nginx server we first need to know either the name of the docker container or the container id. Each container has a unique name and a id that can be used to issue docker commands. We can name our containers by using ‘- -name’ flag at run command. If we do not specify the name docker will come up with a random but cool name for your docker container. But the container id is automatically generated based on some hash function. So let’s run <strong>docker ps</strong> and see the name and id of your nginx container. You should be getting a similar screen as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*Gcqhec3Jd4m1p1V4sz82uA.png" /></figure><p>We have a container named ‘kickass_bose’ (you might have a different name) running with container ID 99654384943a. The container creation date/time and the status (stopped, paused, up), exposed ports and several other information can be observed. This information indicates that the container has 80 and 443 ports opened, which means nginx is runing on these ports. Now in order to access this server we need to get the IPAddress of the container. Each container will have its own docker generated IPAddress which can be used to access from the host system. Using following command we can get this information.</p><pre>docker inspect kickass_bose | grep IPAddress</pre><p>Using <strong>docker inspect</strong> command we can get the full details of this container, the network interfaces, mounted volumes, configuration information etc. As I mentioned earlier docker commands can be used with container name or container id. Here I have used the container name for my container but you can also use container ID as well. But remembering names is pretty easy than some random numbers. Since we are only concerned of the IPAddress of the container we piped it with a regular expression. (You can simply use docker inspect command without pipelining and see what information you can get about your container.) Using the above command you will see the IPAddress assigned to your container, and using that you will be able to access the home page of nginx server through your browser.</p><p>We can map one of the host port to any container, so it can be accessed even from remote machines. To do that we have to use the <strong>-p </strong>flag with HOST_PORT:CONTAINER_PORT. Now the container port should be exposed by the container in order for this to work. Since nginx container by default exposes 80 and 443 port we can use one of that to bind with a host machine port.</p><pre>docker run -d --name nginxServer -p 8080:80 nginx</pre><p>There is nothing new in this command, we simply named the container and mapped the two ports. So now you should be able to access your second nginx container simply by accessing <a href="http://localhost:8080/">http://localhost:8080</a></p><p>Now run <strong>docker ps</strong> again, you should be able to see two nginx servers running. You can run any number of nginx containers (limited by your computing resources) concurrently with other apache containers, IIS containers etc. Each container can have different settings, different programming languages, different run time environments etc.</p><p>The other advantage of docker since its lightweight, the speed of execution. You can start, stop, instantiate, terminate any container in matter of seconds. Let’s stop our second nginx container by issuing the following command</p><pre>docker stop nginxServer</pre><p>This will stop the container and no one can access this container. If you try to access <a href="http://localhost:8080/">http://localhost:8080</a> again you will get an error page. Now if you run <strong>docker ps </strong>you will only see one container running. Using the <strong>-a</strong> flag we can list all the containers in our machine. By default <strong>docker ps</strong> would only list the active running containers.</p><pre>docker ps -a</pre><p>Above command should list the nginxServer container and indicate its status as stopped. You can start the container again by issuing</p><pre>docker start nginxServer</pre><p>It would bring up the nginx server in quick time. So, imagine each container contains a web application and you can just switch it on/off the service using above commands. This opens up many possibilities that were not even in our wildest dreams few years back.</p><p>Is that all you can do with Docker containers? Nope. This is just one of many use cases. There are several ways you can use docker containers to deploy your desired application. This was just to give an introduction to docker commands, hope it was a worthwhile read. Happy dockering!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1a06fde18fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/docker-captain/docker-basics-f1a06fde18fb">Getting started with Docker</a> was originally published in <a href="https://medium.com/docker-captain">Docker Captain</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up a dev environment using Docker]]></title>
            <link>https://medium.com/docker-captain/setting-up-a-dev-environment-using-docker-78ad783a410a?source=rss----1f3d08356982---4</link>
            <guid isPermaLink="false">https://medium.com/p/78ad783a410a</guid>
            <category><![CDATA[lamp-stack]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ridwan Shariffdeen]]></dc:creator>
            <pubDate>Sat, 14 Jan 2017 14:24:40 GMT</pubDate>
            <atom:updated>2017-01-14T14:24:27.990Z</atom:updated>
            <content:encoded><![CDATA[<p>It has been a pain for the developers when it comes to setting up a dev environment on a new PC or a formatted PC. Back in those days I just wished if we could just run one command and boom! everything I want is up and running. Well, now that is possible with Docker. Using docker we can now create multiple dev environment which was not possible at all unless we use a VM. If you are developing web application on PHP 5.5 and want to migrate to Ubuntu 16.04 but you can’t because Ubuntu 16.04 supports PHP 7 and you are not sure downgrading to PHP 5.5 would solve the problems, this is a solution you can try since Docker isolates the host environment and provide a containerized environment to deploy your applications. Which means, you can run PHP 5.5 applications using docker on Ubuntu 16.04 without downgrading the existing PHP 7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*BNebfouCy-Vu03uFvxcJtw.jpeg" /><figcaption>developer need to setup multiple languages and multiple tools</figcaption></figure><p>Let’s setup a dev environment for web application development to see how it works. The art of dockerization is identifying decomposable components and designing a architecture that is easily pluggable and easy to maintain. So if we take a simple web application we need a web server, database server, programming environment and optionally a load balancer. For this exercise lets create a simple setup which includes a Apache Server, MySQL Server and PHP 5.5 environment. First lets setup a MySQL server using Docker with the following command</p><pre>docker run -d --name Database_Server --restart always -e MYSQL_ROOT_PASSWORD=root mysql:5.5</pre><p>This command will pull mysql image with the tag 5.5 and instantiate a container named “Database_Server”. If you noticed we have used some additional parameters (which are simple to understand) with Docker run command. Docker run accepts many flags and parameters which gives us the flexibility to modify the container behavior as we wish. You can find the full list of parameters for Docker run command <a href="https://docs.docker.com/engine/reference/commandline/run/">here</a>, I will explain the ones I used above.</p><ul><li><strong>d </strong>or <strong>- -detach </strong>is a flag used to indicate the running mode of the container. There are two modes you can choose the container to run from which are the default “foreground” mode or the detached “background” mode. Simply put in foreground method the container would exit once the command it run exit(or once you exit the interactive shell). Background mode can be used to keep the container alive until we explicitly stop the container. More details on that can be found <a href="https://docs.docker.com/engine/reference/run/#/detached-vs-foreground">here</a>. By design, containers started in detached mode exit when the root process used to run the container exits.</li><li><strong>- -name </strong>followed by a string (a name) would set the container name to that specified string. Each container has a unique name and a container ID to identify the container within the host.</li><li><strong>- -restart </strong>flag is used to set the restart policy of the container. Docker daemon can restart your container (if stopped by failure) according to the policy we set. If MySQL server process exit due to some exception, the container would automatically stop since that is the root process used to run the container. Hence, we need some sort of restart mechanism to start our containers, thankfully Docker provides that. You have several restart policies given by docker. Possible options are : no, on-failure[:max-retry], always, unless-stopped.</li><li><strong>e </strong>or <strong>- -env </strong>followed by a key=value combination would set the value as a environment variable in the docker container. These environment variables are specific to the container we are running. In this case we pass the ROOT_PASSWORD for the MySQL database. You can find more environment variables you can set for the MySQL container <a href="https://hub.docker.com/_/mysql/">here</a>.</li></ul><p>Once you enter this command, you will get a hash string which is the ID of the container. You can use <strong><em>docker ps</em></strong> to verify that a container named Database_Server is up and running. The MySQL image with tag 5.5 has the bash installed on it (usually it is not installed) so we can use <strong><em>docker exec -it Database_Server bash </em></strong>to open a bash inside the container. Then, we can use any MySQL command we use in a normal bash to execute inside the container. You can check the logs of the container by using <strong><em>docker logs Database_Server.</em></strong></p><p>Now that we have a MySQL server up and running what we need is a PHP environment and a Apache server to serve our web pages. You can either use two different containers one for PHP and Apache and link these together or use one container that has both. I prefer to use one container which has Apache installed with PHP 5.5. So let’s go ahead and instantiate a container with both Apache and PHP. First you need to create your own directory which will be used as the web root directory of the container. It doesn’t have to be in your host /var/www/html instead you can define your own folder.</p><pre>docker run -d --name Web_Server --restart always -p 80:80 -v &quot;$PWD&quot;:/var/www/html  --link Database_Server:dbserver php:5.5<strong>-</strong>apache</pre><p>There are few additional parameters I have used here to instantiate my Apache container.</p><ul><li><strong>-p </strong>or <strong>--published </strong>followed by a mapping (ABC:DEF) would publish a containers port to one of host port. The order is HostPort:ContainerPort. In our use case we publish 80 port with host 80 port. If we don’t specify a mapping and instead just a port then docker would automatically map the given port of the container to a random port in the host.</li><li><strong>-v </strong>or <strong>--volume </strong>followed by a mapping (A/B/C:D/E/F) would mount a volume in the host. Additionally we can specify modes of mounting (read only/read-write etc). Here we mount the ‘/var/www/html’ directory of the container to the current directory of the host.</li><li><strong>--link </strong>followed by a mapping (A:B) will link containers. We can refer containers within containers by using this setup. For our web applications we need to communicate with the database server. Hence we need to know the Docker IP address of the container, but with this option we can easily use a link that can be used as the host name and docker will automatically map the correct IP address to that. So we do not need to query the IP address of the database server manually and set it up.</li></ul><p>You can verify that your web server is working by including a index.html file in your current directory and accessing it using your web browser with <a href="http://localhost./">http://localhost</a></p><p>Now, everything works fine! We have a working web server linked with a database server. But, this only solves the problem partially. We can’t remember each and every parameter for the run command when we setup a dev environment for a new machine. The above example we might be able to remember the exact command but when it comes to different containers remembering this would be not practical. On the other hand what we desire was one simple command to get this up and running for us. This is where <strong>docker-compose </strong>gives you the added advantage. Compose is a tool for defining and running multi-container Docker applications. First, lets check if you have docker-compose installed in your machine using the command “<strong>docker-compose --version</strong>” and if it doesn’t recognize your command you should install docker-compose. <a href="https://docs.docker.com/compose/install/">Click here</a> to see instructions.</p><p>Now the idea is simple, we need to create a docker-compose.yml file which captures all the commands we ran earlier. This way we can use docker-compose to run the same commands to instantiate all the containers we require in one command. That’s pretty cool rite? let’s try this out.</p><p>First we need to define the containers using the syntax of docker-compose. You can find more details on that <a href="https://docs.docker.com/compose/compose-file/">here</a>. For the above setup the docker-compose file is as follows</p><pre><strong>Web_Server:<br>  image: </strong>php:5.5<strong>-</strong>apache<br>  <strong>restart: </strong>always<br>  <strong>container_name: </strong>Web_Server<br>  <strong>volumes:<br>    </strong>- /var/run/docker.sock:/tmp/docker.sock:ro<br>    - ./logs/apache2:/var/log/apache2<br>    - ./html:/var/www/html<br>    - /etc/localtime:/etc/localtime<br>  <strong>environment:<br>    </strong>- VIRTUAL_HOST=example_host<br>  <strong>links:<br>    </strong>- Database_Server:dbserver<br>  <strong>ports:<br>    </strong>- 80:80<br><br><strong>Database_Server:<br>  container_name: </strong>Database_Server<br>  <strong>image: </strong>mysql:5.5<br>  <strong>restart: </strong>always<br>  <strong>volumes:<br>    </strong>- /etc/localtime:/etc/localtime<br>  <strong>environment:<br>    </strong>- MYSQL_ROOT_PASSWORD=root</pre><p>I have additionally linked the host clock and container clock so the clocks are synced (which is useful when debugging), and I have mounted the logs directory for Apache in one of the folders. Using this docker-compose.yml file we can use the following command to instantiate the dev environment</p><pre><strong>docker-compose up</strong></pre><p>The above command should be initiated within the directory the docker-compose.yml file is or we can specify the file using the <strong>-f </strong>parameter. The above command will instantiate all defined containers. If we have multiple definitions and only need certain containers to be started we can use the same command followed by the container names. There are more controls we can use to configure the way our containers would start (start up order, network config, volume containers etc.) using docker-compose. But, for this exercise this would suffice.</p><p>In order to check the status of docker containers we usually use <strong>docker ps </strong>command which would list the status of all the containers running in our machine. If we want to know the status of the containers defined in our docker-compose file we can use the command <strong>docker-compose ps</strong> which is similar to previous command but filters the containers we require.</p><p>I didn’t cover all the scenarios of setting up a dev environment, but I hope this would help you to get an idea on how we can utilize docker to setup our own environment. There are multiple ways you can create your dev environment, this is just one simple way to elaborate the usage of docker-compose. If you have any query do comment below I will help to the best of my knowledge.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78ad783a410a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/docker-captain/setting-up-a-dev-environment-using-docker-78ad783a410a">Setting up a dev environment using Docker</a> was originally published in <a href="https://medium.com/docker-captain">Docker Captain</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Volumes]]></title>
            <link>https://medium.com/docker-captain/docker-volumes-d55d18aafbc0?source=rss----1f3d08356982---4</link>
            <guid isPermaLink="false">https://medium.com/p/d55d18aafbc0</guid>
            <category><![CDATA[docker-volume]]></category>
            <category><![CDATA[data-container]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[busybox]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ridwan Shariffdeen]]></dc:creator>
            <pubDate>Sat, 14 Jan 2017 14:17:43 GMT</pubDate>
            <atom:updated>2017-01-14T14:17:31.695Z</atom:updated>
            <content:encoded><![CDATA[<p>So far the most complicated concept to understand with the over-whelming number of terminology docker introduces, is docker volume. Traditionally a volume is a logical drive which is a storage area accessible within a file system and typically resident in a partition of a hard disk. In this article, I will be explaining the docker concept of volumes and how it is useful to persist data in your containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBhanIGgaaW4Y7A99A9Iqw.jpeg" /></figure><p>First, lets take a look at how docker works, in my previous articles I explained the high-level technology of Docker and the primary concepts of Docker which defines the rest of the terminology. Docker images are the base of everything and it’s a stack of read-only layers where in each layer a Docker command is recorded. When we start a container from such a image, Docker engine takes the read-only stack of layers and add a read-write layer on top of it where the changes are applied. It also make sure that the changes in read-write layer hides the underlying original file in the read-only layer. As usual Docker has a name for this technology too, Union File System; combination of read-only layers with a read-write layer on top.</p><p>Within the Union File System, Docker came up with the concept called <strong>volumes</strong>, which enabled us to persist data and share between containers. They are foreign objects out of the Union File System which can be mounted with either read-only or read-write permissions.</p><p>Docker volume can be looked at in many ways, the primary way to categorize volumes are</p><ul><li>Data Volume</li><li>Data Volume Container.</li></ul><p>There are three main use cases for Docker data volumes</p><ol><li>To keep data around when a container is removed</li><li>To share data between the host filesystem and the Docker container</li><li>To share data with other Docker containers</li></ol><p>Let’s take a look how we can make use of volumes to persist data. The easiest way to achieve this is to create volumes from the host machine. To demonstrate the idea, I will be using Ubuntu:14.04 image. Let’s spin up a container and list the directory in /var</p><pre>docker run Ubuntu:14.04 ls /var</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*ZQj9XgZOGnrv0T76KOSc8A.png" /><figcaption>Content inside /var of the container</figcaption></figure><p>Now lets, mount a directory in our host system to /var and run the same command as above. I created a sample directory with a hello.txt document inside it to demonstrate the example.</p><pre>$docker run  -v ~/sample:/var ubuntu:14.04 ls /var</pre><pre>hello.txt</pre><p>As you can see the content inside the /var directory of the container we ran is the same as the content in the new directory we created. This way anything the container writes to the /var directory will be persisted as long as the content exist in ~/sample directory we mounted on. Additionally we can specify if the volume in read-only or read-write mode to prevent unwanted modifications.</p><p>This is very useful to modify configuration files, data files and installation files inside containers which needs instant updates and dynamically loaded into the container. As we know contents inside docker container is the same as instantiated from the image. This way we can freeze the programs we don’t want to be modified later by the user and allow only certain programs to be altered at run-time.</p><p>Now, let’s have a look at the more complex idea of docker volumes using another container. Yeah! that’s right, we can use a container as a shared medium between multiple containers without running any program on top of it. As I explained in my previous articles, a container would be live only as long as the primary/initial program (PID 1) is running. Since data containers doesn’t require any program, it will not be live, but will get the job done. How to build a good data container is a question that is repeatedly asked in the docker community. The main objective of a data container is to store data and only that. It shouldn’t run any application, it should be small and simple that would not cause problems at the production level which would be hard to troubleshoot.</p><p>Let’s have a look how we can make use of a data container, on a docker eco-system. For this example, I will be using the BusyBox image (<a href="http://www.busybox.net/">BusyBox</a> is a very good ingredient to craft space-efficient distributions) which is most light-weight container. First, we spin up a data container with a directory named <strong>foo</strong></p><pre>docker run -v /foo --name data-container busybox</pre><p>Now lets spin up a Ubuntu container and create a file named bar.txt inside /foo directory which is mounted in data-container volume.</p><pre>docker run --volumes-from data-container ubuntu:14.04 touch /foo/bar.txt</pre><p>Finally, lets spin up another container with data-container volume so we can list the content of /foo directory. Remember original Ubuntu container doesn’t have a directory named /foo and the busy box didn’t have a bar.txt file in it.</p><pre>docker run --rm --volumes-from data-container ubuntu:14.04 ls /foo</pre><p>You will see the output of /foo directory with a file named bar.txt which we created earlier using Ubuntu container. So, the idea is very simple we can use multiple containers but one container to share data between them. This comes pretty handy when you need to backup data and remove the tedious task of running multiple commands in all your containers. Using docker commands like <strong>export </strong>and <strong>import </strong>we can create backups of the data-container and migrate to different servers easily. More on the application later. For now, my intention was to give you an idea of what docker volume is and how we can leverage the benefit of it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d55d18aafbc0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/docker-captain/docker-volumes-d55d18aafbc0">Docker Volumes</a> was originally published in <a href="https://medium.com/docker-captain">Docker Captain</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Multiple versions of AMP in One Host]]></title>
            <link>https://medium.com/docker-captain/multiple-versions-of-amp-in-one-host-6e107c836cd8?source=rss----1f3d08356982---4</link>
            <guid isPermaLink="false">https://medium.com/p/6e107c836cd8</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[lamp-stack]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Ridwan Shariffdeen]]></dc:creator>
            <pubDate>Sat, 14 Jan 2017 14:02:42 GMT</pubDate>
            <atom:updated>2017-01-14T14:08:20.195Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-lzr4PaP0k1RiJqhKPDHEA.jpeg" /><figcaption>Working on multiple projects on different environments</figcaption></figure><p>When you are working on multiple projects with tight deadlines it becomes a pain in the neck to change your host environment to match the project requirements. Not only the hassle but the risk of ruining your almost optimum development environment which worked fine since the beginning of time, now needs to be altered. Working on multiple machines or virtual machines can solve the problem but the time for context switch could be a concern. So why not use docker container technology to solve this problem of environment isolation.</p><p>Few days back one of my friends tried Docker and was interested to use docker to orchestrate his development environment using Docker. The problem he was facing and actually a common issue for most linux developers is software change management. The scenario goes like this, he was doing well with LAMP setup of PHP 5.5 and MySQL 5.7 until he got a project which required him to use MySQL 5.5, which he thought should be a piece of cake and started to downgrade the MySQL version. He followed few tutorials here and there and was able to successfully downgrade to MySQL 5.5 but only to find out later that it was not working as expected. Spending hours to troubleshoot and figure out what went wrong, despite the fact there is a deadline to meet in the project he was frustrated and running out of safe options. This is where Docker came to help (obviously not a smooth solution but gets the problem solved).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*DAo1XU8WipNdMSI6eSdYFA.png" /></figure><p>Here is how you can easily set up different versions of software and use them at the same time without conflicting the resources of one another. Following docker-compose file is a simple setup to use two PHP versions and MySQL versions on the same host and complimentary tool phpmyadmin to make it feel like home. Let’s assume you are running Ubuntu Xenial which by default is packaged with PHP7 and MySQL 5.7. Now we want to use PHP 5.5 and 5.6 with MySQL 5.5 and 5.6 versions all at the same time without compromising the host setup.</p><pre>version: &#39;2&#39;<br>services:  <br> web55:    <br>  image: php:5.5-apache<br>  ports:      <br>   - &quot;7070:443&quot;    <br>  volumes:      <br>   - ./web55/html:/var/www/html      <br>   - ./web55/php5/apache2/php.ini:/etc/php5/apache2/php.ini<br>   - ./web55/php5/cli/php.ini:/etc/php5/cli/php.ini  <br>   - ./web55/apache_logs:/var/log/apache2     <br>   - /etc/localtime:/etc/localtime    <br>  links:      <br>   - db55      <br>   - db56 <br>  restart: always    <br>  container_name: dev_web_55  <br> <br> web56:    <br>  image: php:5.6-apache    <br>  ports:      <br>   - &quot;7071:443&quot;    <br>  volumes:      <br>   - ./web56/html:/var/www/html      <br>   - ./web56/php5/apache2.php.ini:/etc/php/5.6/apache2/php.ini<br>   - ./web56/php5/cli/php.ini:/etc/php/5.6/cli/php.ini      <br>   - ./web56/apache_logs:/var/log/apache2     <br>   - /etc/localtime:/etc/localtime   <br>  links:      <br>   - db55<br>   - db56      <br>  restart: always    <br>  container_name: dev_web_56  <br> <br> db55:    <br>  image: mysql:5.5    <br>  expose:      <br>   - &quot;3306&quot;    <br>  volumes:      <br>   - ./db55/config:/etc/mysql  <br>   - ./db55/mysql_logs:/var/log    <br>   - /etc/localtime:/etc/localtime  <br>  environment: <br>   MYSQL_ROOT_PASSWORD: 1234    <br>  restart: always    <br>  container_name: dev_mysql_55   </pre><pre> db56:    <br>  image: mysql:5.6   <br>  expose:      <br>   - &quot;3306&quot;    <br>  volumes:      <br>   - ./db56/config:/etc/mysql <br>   - ./db56/mysql_logs:/var/log<br>   - /etc/localtime:/etc/localtime    <br>  environment: <br>   MYSQL_ROOT_PASSWORD: 1234    <br>  restart: always    <br>  container_name: dev_mysql_56   </pre><pre> phpmyadmin:    <br>  image: phpmyadmin/phpmyadmin<br>  volumes:      <br>   - /etc/localtime:/etc/localtime    <br>  links:      <br>   - db55      <br>   - db56   <br>  ports:      <br>   - &quot;9090:80&quot;    <br>  environment:      <br>   PMA_HOSTS: db55,db56   <br>  restart: always  <br>  container_name: dev_phpmyadmin</pre><p>This docker-compose configuration file consists of 5 containers namely dev_web_55, dev_web_56, dev_mysql_55, dev_mysql_56 and dev_phpmyadmin. Note the naming convention I used to depict the version of the software. I have also linked each web container to both MySQL containers and same for phpmyadmin. This way you can have multiple combinations for different projects. If you are not familiar with the notations please see my article on <a href="https://medium.com/@rshariffdeen/learning-docker-terminology-d474fa3640a4">Docker terminology</a> and <a href="https://medium.com/@rshariffdeen/setting-up-a-dev-environment-using-docker-78ad783a410a">docker-compose usage</a>. You can also refer the official <a href="https://www.google.lk/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwiNnqy9hL3RAhWLOo8KHd9uCqQQFggYMAA&amp;url=https%3A%2F%2Fdocs.docker.com%2F&amp;usg=AFQjCNEGIOiP19F1JIG_vWz4-3ywUayz3Q&amp;sig2=PcuIU7Bf4UfBEKbTlKIKuw&amp;bvm=bv.144210762,d.c2I">Docker documentation</a> which is self-explanatory and gives you handful of examples to understand.</p><p>Now all you have to do is correctly <a href="https://medium.com/@rshariffdeen/docker-volumes-d55d18aafbc0">volume</a> the settings you want inside the container. I have linked the html folder and few php settings so I can change these settings on run-time just as you do for your host setup. You can also volume the Apache settings and any other director/file as you prefer.</p><p>Once everything is setup, you can use PHP 5.5 by accessing with the port 7070 and PHP 5.6 with the port 7071. Within the application you can connect to different MySQL hosts using the host name db55 and db56. I have also included a multi host phpmyadmin which you can access using the port 9090 and allows you to login into both db55 and db56 containers. Hope this enlighten you to try out Docker to deploy multi version tools. Happy development!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e107c836cd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/docker-captain/multiple-versions-of-amp-in-one-host-6e107c836cd8">Multiple versions of AMP in One Host</a> was originally published in <a href="https://medium.com/docker-captain">Docker Captain</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>