
Today you may frequently hear terms like Devops , Virtualization and of course Cloud . In the following lines we will talk about them and also to make the most fun thing present a real application of all these concepts.
Virtualization is a very broad concept and has different applications depending on the level where it occurs, we have already talked about another time Copicloud , where virtualization goes to the extreme, becoming a "cloud."
Today we will focus on another level of virtualization, aimed at both developers and system administrators, which is why I present the Docker tool.
For being currently one of the tools preferred in the world Devops.
Today we will focus on another level of virtualization, aimed at both developers and system administrators, which is why I present the Docker tool.
For being currently one of the tools preferred in the world Devops.
What is Devops?
"DevOps is a response to the interdependence of software development and IT operations."
Devops defines a software creation methodology, as well as a way of integration between developers and systems administrators, to achieve the creation and start-up of software in a faster way, with higher quality standards, lower cost and allowing a Higher frequency of put in production for the new versions.
It is a rather confusing term and in the network try to define it in multiple ways, even from the opposite approach, what is not Devops?
Devops defines a software creation methodology, as well as a way of integration between developers and systems administrators, to achieve the creation and start-up of software in a faster way, with higher quality standards, lower cost and allowing a Higher frequency of put in production for the new versions.
It is a rather confusing term and in the network try to define it in multiple ways, even from the opposite approach, what is not Devops?
The magic of Docker
One of the most fashionable tools for streamlining the interdependence between development and systems is Docker, a lightweight virtualization solution for building software containers .
These containers group everything necessary for the software, code , tools , systemlibraries , configurations , tuning, permitting scheme to work. etc.
It also has a simple interface for creating , executing and sharing software containers.
These containers group everything necessary for the software, code , tools , systemlibraries , configurations , tuning, permitting scheme to work. etc.
It also has a simple interface for creating , executing and sharing software containers.
Light Virtualization What is it?
When we talk about virtual machines, it sounds like tools like VirtualBox , or VMware , given its great popularity, as well as other alternatives like QEMU or Microsoft Hyper-V also very widespread, this type of solutions is called Hypervisors.
The hypervisor emulates the underlying hardware and allows the different operating systems that are installed in it to think that they are unique owners of the system, within this mega pack we run all the services so that our application can work as well as other innate services to the operating system Virtual (consuming resources).
Docker's philosophy, unlike the previous one, tries to layer the application and create specific containers for each part of the application or service, for example if we think of a web application, SPA , "Single-page application" we can clearly differentiate , A part of programming in the server or backend , a part of programming in the client or frontend , as well as a storage, database or static files, with this philosophy we create independent containers and we make them know each other and talk to each other.
In addition the containers share the same operating system, are very fast to deploy, consume less resources than the complete VMs and also can be shared much more comfortable, their size is very small, order of megabytes, while the VMs, have order Of gigabytes.
The hypervisor emulates the underlying hardware and allows the different operating systems that are installed in it to think that they are unique owners of the system, within this mega pack we run all the services so that our application can work as well as other innate services to the operating system Virtual (consuming resources).
Docker's philosophy, unlike the previous one, tries to layer the application and create specific containers for each part of the application or service, for example if we think of a web application, SPA , "Single-page application" we can clearly differentiate , A part of programming in the server or backend , a part of programming in the client or frontend , as well as a storage, database or static files, with this philosophy we create independent containers and we make them know each other and talk to each other.
In addition the containers share the same operating system, are very fast to deploy, consume less resources than the complete VMs and also can be shared much more comfortable, their size is very small, order of megabytes, while the VMs, have order Of gigabytes.
I have to say that Docker is not the only alternative to perform this type of virtualization, there are other forms such as cages, LXC, BSD, vServers, OpenVZ. Although it is true that Docker is one of the favorite alternatives.
How to install Docker?
Dear reader, I am sorry to inform you that my intention is not to take a step by step to install and configure Docker, since I do not know your machine. Tell you that this tool is intended to run on Linux machines and does not work natively on Windows or Mac OSX, but do not be scared, since there are executable packages that make use of VirtualBox install a perfect Linux base so you can run your Docker containers On Windows and Macs platforms.
Cloud providers such as Amazon Web Services (AWS) or Digital Ocean , also make efforts in the Docketization of the applications we host, providing us with plugins to make our life easier.
I recommend that you go through the " Install Docker Engine " section of the official page .
I recommend that you go through the " Install Docker Engine " section of the official page .
DockerHub, the image repository
You will be asked where to find Docker images, to create your first containers.
For there is a public directory called DockerHub that contains all kinds of custom images, for many types of projects, from containers with the minimum services to run web applications, PHP or Django , databases in MySql or Postgres , NodeJS or applications More complex like Wordpress , OwnCloud , etc.
As a curiosity for the players, there are containers to create Minecraft or Counter Strike servers .
For there is a public directory called DockerHub that contains all kinds of custom images, for many types of projects, from containers with the minimum services to run web applications, PHP or Django , databases in MySql or Postgres , NodeJS or applications More complex like Wordpress , OwnCloud , etc.
As a curiosity for the players, there are containers to create Minecraft or Counter Strike servers .
The Docker Console
There are many commands to handle the images and containers, it is not interesting to go into detail, since we have a good documentation that we can always consult or the command docker help .
The basic commands can be summarized in the following:
The basic commands can be summarized in the following:
Customize my image, the Dockerfile
Surely at this point you will be thinking, how do I create my personalized image? . Very easy, there are different methods but the most usual is to use Dockerfile .
Dockerfile is a manifesto where you specify the characteristics of your image, additional software that you want installed, libraries, services and configurations. The format of this document always has the same structure:
Dockerfile is a manifesto where you specify the characteristics of your image, additional software that you want installed, libraries, services and configurations. The format of this document always has the same structure:
To learn more about how to write your Dockefile, I recommend that you go back to the official documentation .
Working with multiple containers
The philosopher of Docker tries to separate the layers of our application in different containers.
So for a simple application it is easy to have several containers, and managing them independently can be complex.
For this we have docker-composer , which tries to unify the management tasks of the different containers in a single manifesto, docker-composer.yml .
In this manifest, we declare all the containers necessary for the application to work, along with its relationships and dependencies.
In the last section I propose an example of use for docker-composer.
I'm not a friend of the console
If you do not get along with the command console, do not be scared, there are applications that make your interaction with Docker containers more enjoyable.
In order to not always walk with the terminal, there are several desktop applications with graphical interface, which facilitates the management of containers and images.
For Windows and Macs we have Kitematic , an application very intuitive to use and that has a browser of images of DockerHub.
In order to not always walk with the terminal, there are several desktop applications with graphical interface, which facilitates the management of containers and images.
For Windows and Macs we have Kitematic , an application very intuitive to use and that has a browser of images of DockerHub.
For all platforms, we have the Chrome application, Simple Docker UI .
A practical example
Finally, let's look at some interesting examples of how to install various applications using Docker containers.
Install Wordpress CMS
A good example is to install Wordpress CMS , making use of two containers, one for the application and another for the database. We use only pre-made images available on DockerHub.
We can see in the Kitematic graphical environment that we effectively have both containers removed.
Finally we can access from our browser to the ip address of our container, install the CMS Wordpress and start working.
Additionally one of the indispensable tools to manage and manage Wordpress is PhpMyAdmin . To install it we can proceed in two different ways.
- Customize a Dockerfile , to have an image with the services of both MySQL and PhpMyAdmin.
- Add a new container with the exclusive services of PhpMyAdmin and link it with the MySql container.
A container architecture remains as follows.
Install Django Framework
In another example we simply created a development machine for the Django web framework, this time we created our own image, starting with a Dockerfile and orchestrating the machines we use Docker Composer .
- Step One: Write Dockerfile to build the Django development machine.
* Click on the image to enlarge it
- Step Two: Declare dependencies pip, requierement.
* Click on the image to enlarge it
- Step Three : Write docker-composer , to create all the containers and bind them.
* Click on the image to enlarge it
As we see the environment variables we store them in a separate file "development.env".
An example of such a file is as follows.
* Click on the image to enlarge it
- Step Four: Start the Django application.
Docker-compose run web django-admin.py startproject example. - Step 5: Configure database in the application configuration, making use of previously set environment variables.
* Click on the image to enlarge it
- Step Six: Run Container and Application.
conclusion
I hope you found this tool interesting and encourage you to start using it in your next projects, we would be happy to know your experience with Docker.
If you liked it and you think it may be useful for other readers, do not hesitate to share it on social networks ;-)
No comments:
Post a Comment