Two weeks ago, I went to a docker meetup organized by Docker Saigon, because at Apiumtech we really see the potential of Docker. This meetup was about an introduction to a new version of Docker, it also gave a great overview about Docker in general. (For anyone who is interested in the speech, you can find it here.


A related postDockerize A Multi-Module Scala Project With SBT


 


As you might have noticed, Docker is one of the hot trends recently. Why is it so hot? In my opinion, because it makes our lives a lot easier. With Docker, setting up an environment that can run anywhere from your local machine to your production server is painless. You will almost never be able to make the excuse of “But it works on my machine” again. In this post, I’ll give you a brief introduction to Docker and its latest version 1.9.


 


What is Docker?


Build, ship and run. If you have heart something about Docker you might also have seen or heart that catchphrase somewhere. Docker claims to provide an open platform to package your application in a container that could be moved and executed anywhere. And it does exactly what it promises. Currently, Docker is only supporting applications that run on Linux, Docker for Windows applications is already “on its way”, according to thenewstack.io.


Build


First, let’s see how can we package an application with Docker. In order to run docker, you need to install it. Installation instruction can be found Here. One thing to keep in mind is that Docker is currently support 64-bits systems only.


Once you have Docker installed on your machine, you’ll need a dockerfile. Dockerfile is a configuration file, where we can describe all the frameworks, languages and dependencies needed by our application. Normally, a dockerfile might look similar to this:


 docker build


The FROM command allow you to base your image on other existing images. The RUN command will execute various commands in your new container. The EXPOSE command tells Docker which port should the container be listening to at runtime.


Once your Dockerfile has been created, a docker build command will help you to create an image based on it.


Ship


Docker offers both private and public registries on Docker Hub, in which you can create a repository, push, pull and run your Docker image anywhere. For further information about Docker Hub please go Here.


Run


With Docker, you can run an image by typing this in the command line: docker run image-name , without any further configuration. First, Docker will try to find image-name in your local machine, if it fails, it will look for the image on Docker Hub. An example provided by Docker: docker run hello-world. If your environment has been setup correctly, you’ll see this:


*Some useful Docker commands


 


– Docker ps: list the docker containers that are running on your machine (docker ps -a for showing all the containers on your machine)


– Docker images: list all the Docker images on your machine


– Docker stop / docker rm: stop / remove a container


– Docker rmi: remove an image from your machine


– Docker build: create an image from dockerfile


The Architecture


docker


Docker uses a client-server architecture. There is a Docker daemon that will do the heavy jobs like building, running and distributing images. Docker client will talk to that Docker daemon via sockets or a RESTful API. Docker client and Docker daemon can be installed in the same system or communicating remotely.


In this article, you see the word ‘image’ and ‘container’ a lot. These are important terms if we are talking about Docker, so I would like to go further here.


Images


A Docker image is created by the docker build command. Images can be built on top of each other and can be stored in registries such as Docker Hub. Since an image’s size could be quite large, it was designed so that it comprises of multiple layers. This way, only a minimum amount of data will be transferred over the network when an image is updated.


Containers


A container is an instance / a runtime object of an image. Whenever an image is run, a container will be created for it. One image can have multiple running containers.


 


Docker Version 1.9


A few days ago, Docker has released its new version: 1.9, and it was a big release. There are some notable features delivered in this update such as multi-host networking and swarm in production.


Docker Swarm


Docker Swarm is the native clustering for Docker Engine. It allows you to define a cluster, join hosts to it and manage the hosts throughout that cluster.


Multi-host Networking


Docker networking allows you to connect containers regardless of where they are hosted. With this feature, you can create a virtual networks that could be attached to containers, allow them to communicate with each other.


Besides the 2 remarkable features, Docker also introduced a lot of improvements in the new version for example it added a build-arg flag for Docker build and improve the stop signals by adding a STOP SIGNAL Dockerfile instruction. To learn more about the new features of Docker 1.9, please go to this change log. You can also go here to learn about Docker Swarm, and here to learn about Docker Networking.


 


REFERENCES


Thenewstack.io 2015, Docker for Windows is on its way


Docker Saigon Meetup 2015, Docker v1.9 Fundamentals 


Ben Firshman 2015, Announcing Docker 1.9: Production-ready Swarm and Multi-host Networking.