⬆️ ⬇️

Run docker compose on Windows

Docker-compose is a utility that allows you to run multiple containers at the same time, using a single configuration file for the entire stack of services needed by your application. For example, such a situation: start node.js webapp, which needs mongodb to work, compose will build your container with a webapp (traditional Dockerfile) and launch a container with mongodb inside before launching it; can also link them to each other. Which is extremely convenient both in development and in the CI of the application itself. It so happened that Windows users were deprived of the opportunity to use so many convenient tools, since there is still no official support for this OS. And the python version for * nix does not work in windows cmd environments, due to the limitations of the Windows console.



In order to run docker-compose, we can use the Babun console shell. This, so to speak, "pumped" fork cygwin.



So, the recipe for running docker-compose on Windows from the babun console is:



1. Download (~ 280MB!) And install the babun itself, you can learn more about this shell on its homepage babun.imtqy.com ;

2. Unpack the archive (after installation, you can delete the resulting folder) ;

3. Run the install.bat file and wait for the installation to take place;

4. Then in the opened babun window, enter the command:

')

babun update 


And make sure that we have the latest version of the shell (hereinafter, all commands are executed only inside the babun shell) ;

5. If you don't like the default shell babun (zsh is used), you can change it to bash. To do this, enter:



 babun shell /bin/bash 


6. Now we need to install the same Python dependencies that docker-compose lacks. To do this, execute the following commands in turn:



 pact install python-setuptools 


 pact install libxml2-devel libxslt-devel libyaml-devel 


 curl -skS https://bootstrap.pypa.io/get-pip.py | python 


 pip install virtualenv 


 curl -skS https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get-pipsi.py | python 


7. Now we are ready to install docker-compose itself:



 pip install -U docker-compose 


If everything went well, we will see:



 { ~ } » docker-compose --version docker-compose 1.2.0 


If you received an error, error python fcntl or a message about not finding the docker-compose file, try to find the docker-compose file in the / usr / local / bin, / usr / sbin and similar folders, then you can make a symlink to / bin /. or add the missing path to the system PATH.



For docker-compose to work properly, you need to have the console environment configured to work with the docker-machine or boot2docker, as well as the docker client itself must be available in the system's PATH. The official documentation tells perfectly well what docker , docker-machine is and how to work with them.



To enter the environment of our docker host running in docker-machine, do the following:



 eval "$(docker-machine env _)" 


Or the same for boot2docker:



 eval "$(boot2docker shellinit)" 


You can verify that the docker client is working properly like this:



 docker ps 


If we get a list of containers or just table headers, then everything is OK!



 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 


To launch the application stack, go to the directory of our application, where we should already have prepared the docker-compose.yml or fig.yml file. The syntax of the yml file is described here .



Next to run, enter the command:



 docker-compose up 


If you want to run in the background, add -d. Compose will build the desired image and launch it according to your docker-compose.yml file.



That's all.



Thank you for your attention, I hope it was useful.



ps I deliberately did not talk about launching compose as a container, since I consider it uncomfortable.

Source: https://habr.com/ru/post/260329/



All Articles