From 1efedd6e17cf2540fd0a9f839c95970f9d79fd1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 9 Nov 2016 15:11:42 -0500 Subject: [PATCH] Add support for docker-compose volumes --- README.md | 48 +++++++++++++++++++++++++++++++++++++++++---- bin/babun-docker.sh | 5 ++++- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7ebde7b..268b3c2 100644 --- a/README.md +++ b/README.md @@ -10,17 +10,25 @@ This program installs [winpty](https://github.com/rprichard/winpty), sets the en This allows running commands that "enter" in the container, as for example those that use `-it` and end in `bash`: -```docker run -it -v $(pwd):/var/www debian bash``` +```bash +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: -``` +```bash docker run -d -v $(pwd):/var/www ubuntu ping google.com ``` -**Note**: After installing **babun-docker** (this program), you don't have to "use" another program. You can keep using the ```docker``` commands as normal. +The shared folders (drives) inside the docker-machine (VirtualBox virtual machine) are mounted in two different directories to make it compatible with `docker` and `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: + +```bash +docker ps +``` + +**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. ## Installation @@ -39,7 +47,7 @@ curl -s https://raw.githubusercontent.com/tiangolo/babun-docker/master/setup.sh babun-docker-update ``` -* From Babun, use Docker as you would normally, for example: `docker ps`. +* From Babun, use Docker as you would normally, for example: `docker ps`. 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`. @@ -82,6 +90,38 @@ docker-machine stop $babun_docker_machine_name ## What's new +#### 2016-11-09: +Now the shared folders are mounted in two directories inside the VirtualBox virtual machine to make it compatible with `docker-compose`. + +You can start and set up **babun-docker** and all the shared folders with any `docker` command, as: + +```bash +docker ps +``` + +And have a `docker-compose.yml` file with: + +```yml +version: '2' +services: + server: + build: ./server + volumes: + - ./server/app:/app + ports: + - 8081:80 +``` + +...note the relative mounted volume in `./server/app:/app`. + +And then bring up your stack with: + +```bash +docker-compose up -d +``` + +and it will work (because the shared folder paths that `docker-compose` uses are also mounted in the virtual machine). + #### 2016-08-17: * Fix for the command `docker login`, see PR [24](https://github.com/tiangolo/babun-docker/pull/24) by [jpraet](https://github.com/jpraet). diff --git a/bin/babun-docker.sh b/bin/babun-docker.sh index 565205d..d5bfb3c 100644 --- a/bin/babun-docker.sh +++ b/bin/babun-docker.sh @@ -26,9 +26,11 @@ function docker { if [[ -f "$babun_docker_virtualbox_bin" ]] ; then for drive in $(echo $babun_docker_volumes | tr '\n' ' ') ; do windows_drive=$(cygpath -d /cygdrive/$drive) + windows_driveb=$(cygpath -d /$drive) if [[ -z $("$babun_docker_virtualbox_bin" showvminfo $babun_docker_machine_name | grep "Name: '$drive'") ]] ; then echo "$babun_docker_feedback Setting VirtualBox shared folder for drive $drive" "$babun_docker_virtualbox_bin" sharedfolder add $babun_docker_machine_name --name $drive --hostpath $windows_drive --automount + "$babun_docker_virtualbox_bin" sharedfolder add $babun_docker_machine_name --name $drive --hostpath $windows_driveb --automount else echo "$babun_docker_feedback VirtualBox shared folder for drive $drive was already set" fi @@ -45,9 +47,10 @@ function docker { for drive in $(ls /cygdrive); do echo "$babun_docker_feedback Volumes, creating directory for drive: $drive" docker-machine ssh $babun_docker_machine_name "sudo mkdir -p /cygdrive/$drive/" + docker-machine ssh $babun_docker_machine_name "sudo mkdir -p /$drive/" echo "$babun_docker_feedback Volumes, mounting drive: $drive" - #docker-machine ssh $babun_docker_machine_name "sudo mount -t vboxsf $drive /cygdrive/$drive/" docker-machine ssh $babun_docker_machine_name 'sudo mount -t vboxsf -o "defaults,uid=`id -u docker`,gid=`id -g docker`,iocharset=utf8,rw"' "$drive /cygdrive/$drive/" + docker-machine ssh $babun_docker_machine_name 'sudo mount -t vboxsf -o "defaults,uid=`id -u docker`,gid=`id -g docker`,iocharset=utf8,rw"' "$drive /$drive/" done IFS='' fi;