When you hear people talking about Docker and / or Docker Compose, it sounds exciting but it sounds a bit like Chinese because everything is too technical.
The learning curve is not exactly smooth, although thanks to Youtubers like "Pelado Nerd" you can save yourself a lot of headaches.
I love Docker, and the more I know about this type of virtualization so close to the operating system (which has nothing to do with virtualizing machines with VirtualBox and the like), the more I virtualize things.
You can virtualize development environments, cms’s, online stores.
With Docker you can even virtualize applications (at least on Linux), you can find on the web wide world for example, how to virtualize with docker compose the famous sublime text.
Docker is a software virtualizer.
To catch it fast.
It is as if you installed a virtualbox, but without installing the operating system, only the software in question. And it doesn't matter if you use Ubuntu or Windows, they will all work exactly the same in isolation from your environment.
Docker installs images and containers, always using your operating system.
In Docker an image is software, mysql, wordpress, drupal.
In Docker a container is the instance of an image.
I explain the latter better to you.
You can install 3 different wordpress, each of those wordpress is going to be the site or domain that you will upload to your hosting, and that you will probably first prefer to create it and test it locally.
When you do a "docker build" or "docker up", the first thing Docker will do is create the images, and then the containers.
If your docker-compose file contains the "ingredients" for Apache, Nginx, WordPress, and Phpmyadmin, this will automatically create each of those images.
Then you will create a container for each of those images.
The container is an instance of the image. As if the image were a template and the container an extension of it.
And if we clone this environment, or create another that also uses Apache, it will use that same image.
That is to say. If we have 5 sites virtualized with Docker that use Apache, it will not install 5 apaches, but it will not install only 1 and it will be shared for all containers.
The magic of docker is such, that you can run php 5 environments, while your machine remains at version 7.2, or it just doesn't have php.
The way everything works in docker is by forming a network between the containers, where they are seen and understood through the ports.
For example, you install a mysql specifying as port 8090.
You install 3 different cms’s, which will need mysql. Well, you tell these that their mysql is on port 8090. And now ...
You install a software with a php 4, uuuuuuuuuuuuuuuuu, for port 9091.
In the browser you will use localhost: 9091 and it will appear that the software is on your own machine.
You can also go into the container, and work inside and run things in it, which would be the analog of being in the console of a virtualbox.
Well, if Docker is magic, docker compose has no words.
Docker compose is a little file, where you describe the list of images and containers that you want to create, and how they interconnect between them.
It is like a cooking recipe, where you are going to declare what ingredients you use and how you mix them.
This is done with the command docker-compose.yml
And when you go to the folder of that file, you do "docker-compose up".
Then the thermo-mix acts 😀
Example of a wordpress docker-compose:
services: php: image: wordpress restart: 'always' ports: - 0.0.0.0:80:80 depends_on: - mysql links: - mysql volumes: - ./data/www:/var/www/html mysql: image: mysql restart: 'always' volumes: - ./data/mysql:/var/lib/mysql environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: my_site MYSQL_USER: root MYSQL_PASSWORD: root
Where "volumes" is the volatile data.
Look at mysql, volumes. We are making mysql data to be in a shared folder with the host. ("Host" is our real machine, "container" is inside docker)
That is, when we zip the folder where the docker-compose.yml file is located, and we take it to another place, the new container will "hook" the mysql data again.
Useful docker and docker compose links
By the way, official Docker site and its documentation
If you want to install it, you will find by google how to do it from your operating system.
For example to install it from ubuntu 18 https://www.digitalocean.com/community/tutorials/como-instalar-docker-compose-en-ubuntu-18-04-es
If you have never tried docker-compose, when you do it will be like eating pipes, you will not want to stop learning and using it more and more.