Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Commit

Permalink
Add support for docker-compose volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed Nov 9, 2016
1 parent 0ad7fdc commit 1efedd6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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`.

Expand Down Expand Up @@ -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).

Expand Down
5 changes: 4 additions & 1 deletion bin/babun-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 1efedd6

Please sign in to comment.