If you are using Cygwin, you should be using Babun. It's an improved Cygwin. Nevertheless, the latest versions of babun-docker work in Cygwin too.
This program installs winpty, sets the environment variables and creates a function to embed
docker, and to allow non-tty connections.
This allows running commands that "enter" in the container, as for example those that use
-it and end in
docker run -it -v $(pwd):/var/www debian bash
It also checks if the default docker-machine (the Virtual Machine) is running, if not, it tries to start it and set the environment to use it.
And it also sets up shared folders in VirtualBox for each drive in your Windows (although you can configure which drives to use if you want) and mounts them inside the virtual machine (docker-machine), to allow using volumes with Docker (from any drive in your Windows, which is even more than what comes by default with the Docker Toolbox) to allow using commands like:
docker run -d -v $(pwd):/var/www ubuntu ping google.com
The shared folders (drives) inside the docker-machine (VirtualBox virtual machine) are mounted in two different directories to make it compatible with
docker-compose, so you can use normal relative volumes with
docker-compose. You only have to make sure you run a normal
docker command first to start and set up everything. For example:
Note: After installing babun-docker (this program), you don't have to "use" another program. You can keep using the
docker commands as normal. And after running a first
docker command, you can use
docker-compose as you would normally too.
- Install Docker Toolbox.
- Run the bundled Docker Quickstart Terminal that comes with Docker Toolbox to make sure everything is working.
- Turn off the Docker Toolbox Virtual Machine: run
docker-machine stop default(or turn off the Virtual Machine
defaultin VirtualBox) so that babun-docker can do all the needed automatic configurations with the VM turned off.
- Install Babun and start a terminal.
- Run the following command:
curl -s https://raw.githubusercontent.com/tiangolo/babun-docker/master/setup.sh | source /dev/stdin
- To be able to use babun-docker right away without having to close and open Babun run the update:
- From Babun, use Docker as you would normally, for example:
It will take care of configuring the virtual machine, turning it on, sharing volumes, allowing non-tty commands, etc. Whenever it does something for you (automatically) you will see an output like:
-- babun-docker: doing something.
Note: the installation command will get a script from this repository and run it immediately, performing all the needed steps to install everything (the same steps described in "Manual installation"). If you don't want to run it, you can do a manual installation.
Installing docker-babun in Cygwin
If you definitively don't want to use Babun, you can install docker-babun in Cygwin (nevertheless, I highly recommend you Babun).
First you will need to have installed the following packages (installed by default in Babun):
Then you can run the same command as above.
- To update babun-docker, after following the installation instructions, run the command:
Note: if you want to receive email notifications when babun-docker is updated you can "star" this repository (the star button above) and login with GitHub to Sibbell, it will send you notifications automatically with new releases.
- As Docker Toolbox runs in a virtual machine, it uses
docker-machineto comunicate and configure it. If you want to turn the virtual machine off, run:
docker-machine stop $babun_docker_machine_name
- Fix new line CR (Windows style) in setup. PR #37 by @marcelotaube.
- Fix typo in docs. PR #38 by @Jason-Cooke.
Now the shared folders are mounted in two directories inside the VirtualBox virtual machine to make it compatible with
You can start and set up babun-docker and all the shared folders with any
docker command, as:
And have a
docker-compose.yml file with:
version: '2' services: server: build: ./server volumes: - ./server/app:/app ports: - 8081:80
...note the relative mounted volume in
And then bring up your stack with:
docker-compose up -d
and it will work (because the shared folder paths that
docker-compose uses are also mounted in the virtual machine).
winptydownload file explicit, see PR 23 by murrayju.
- Use the latest version of Winpty (0.4.0).
- Now you can run babun-docker in Cygwin (but I still recommend Babun).
- Update winpty to latest version (and make old winpty installs to auto-update).
- Now you can use Bash instead of Zsh.
- You can configure the VirtualBox installation path with the variable
babun_docker_virtualbox_bin. Read more in the Configurations section below.
You can define which specific Windows drives to mount with the variable
babun_docker_volumes(by default babun-docker tries to mount them all). Read more in the Configurations section below.
You can use a separate file in
~/.babun-docker/custom-config.shfor custom configurations. Read more in the Configurations section below.
Improved mounted volumes and ownership (with hints by @olegweb ).
- babun-docker automatically sets up shared folders in your VirtualBox virtual machine (docker-machine) for each of your Windows drives and mounts them inside the virtual machine, to allow using volumes (from any drive in your Windows, which is even more than what comes by default with the Docker Toolbox) with commands like:
docker run -it -v $(pwd):/var/www debian bash
You can configure if you want babun-docker to automatically set up VirtualBox shared folders and volumes with the environment variable
babun_docker_setup_volumes. Set it to "0" if you want to disable that. Read more in the Configurations section below.
You can now specify the name of the docker-machine to use with the environment variable
babun_docker_machine_name, which is set by default to the "default" machine (named "default"). (No pun / tongue twister intended). Set that environment variable to the name of the machine that you want to use (e.g.
babun_docker_machine_name='dev'). Read more in the Configurations section below.
The installation of babun-docker clones the repository and sets up the environment to use the scripts inside it instead of writing it all to the
babun-docker-updatewill update that repository (will update babun-docker) and set up the environment again.
Docker Volumes with Babun
Here is an explanation of how volumes work in Docker and how they work in the Toolbox Virtual Machine: Docker Volumes with Babun.
That's what allows using commands like:
docker run -it -v $(pwd):/var/www debian bash
But all that is implemented automatically in the newest version of babun-docker.
- Go to your home directory:
- clone this repo in the specific directory, like:
git clone https://github.com/tiangolo/babun-docker.git ./.babun-docker
- Enter that directory:
- Source the setup:
The setup will:
- Download and install Winpty to allow using Docker commands that enter a container
- Create a command (function) to update babun-docker, with
- Add itself to the
~/.zshrcfile to run at startup
- Run (
source) the script to fix Docker, wrapping it
The wrapper script (function) will try to call docker, if it fails, it will check what was the failure, try to fix it and run again.
The wrapper / fix will:
- auto-start the default docker machine
- set the environment variables for that default docker-machine
- use winpty (console) to connect to a tty session to avoid errors, as in:
docker exec -it my_container bash
After installing babun-docker, you can configure things with environment variables in the file
- If you want to specify which drives should be used for the setup of VirtualBox shared folders and volumes inside your docker-machine virtual machine set the environment variable
babun_docker_volumesto a list of the drive names separated by spaces, as in "c d". For example:
echo 'babun_docker_volumes="c d"' >> ~/.babun-docker/custom-config.sh source ~/.babun-docker/*config.sh
- If you want to disable the setup of VirtualBox shared folders and volumes inside your docker-machine virtual machine set the environment variable
babun_docker_setup_volumesto "0". For example:
echo babun_docker_setup_volumes=0 >> ~/.babun-docker/custom-config.sh source ~/.babun-docker/*config.sh
- If you want to change the virtual machine to use (if you have configured another virtual machine with
docker-machine) you can set the environment variable
babun_docker_machine_nameto the name of your new virtual machine. For example:
echo babun_docker_machine_name='dev' >> ~/.babun-docker/custom-config.sh source ~/.babun-docker/*config.sh
- If you have VirtualBox installed in a different location (it would be uncommon) you could set the path with the variable
babun_docker_virtualbox_bin, you would have to use Cygwin (Babun) paths, you can use cygpath to convert between Windows and Cygwin paths. It should point to the program "VBoxManage". For example:
echo "babun_docker_virtualbox_bin='$(cygpath -u 'C:\Program Files\Oracle\VirtualBox\VBoxManage')'" >> ~/.babun-docker/custom-config.sh source ~/.babun-docker/*config.sh
This project is licensed under the terms of the MIT license.