psychok7
psychok7

Reputation: 5473

Docker Machine + Docker Compose + Volumes on Ubuntu

So i have beeen using docker-compose in development for a while now on my Ubuntu 14.04 LTS host machine with a local VirtualBox provider (boot2docker inside it).

Only recently i decided to try out docker-machine (because of the integration with Pycharm) but i am running into some issues like for example when i save some new code the docker container is not updated automatically anymore and i think its because i commented out my volumes in my docker-compose.yml web service but if i don't i will get a manage.py not found error so i understood in this here that i should comment it instead.

I have been reading lots of things on the internet and i would like to know if there is a good and simple approach to get docker-machine playing nicely with docker-compose on Ubuntu.

DockerFile

FROM ubuntu:14.04.3
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y \
  build-essential \
  git-core \
  python2.7 \
  python-pip \
  python-dev \
  libpq-dev \
  postgresql-client-9.3 \
  libjpeg-dev \
  binutils \
  libproj-dev \
  gdal-bin
RUN mkdir /vagrant
WORKDIR /vagrant
RUN mkdir requirements
COPY requirements requirements
RUN pip install -r requirements/local.txt
COPY . /vagrant/

docker-compose.yml

postgis:
  image: mdillon/postgis:9.3
  ports:
    - "5432:5432"
  environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: "postgres"
#  volumes:
#    - /etc/postgresql
#    - /var/log/postgresql
#    - /var/lib/postgresql

web:
  build: .
  dockerfile: Dockerfile
  command: python manage.py runserver 0.0.0.0:8000 --settings=xxx.settings.local
#   https://stackoverflow.com/a/31567743/977622
#  volumes:
#    - .:/vagrant
  ports:
    - "8000:8000"
  links:
    - "postgis:postgis"

UPDATE:

when i run the mount command inside my vm i get:

tmpfs on / type tmpfs (rw,relatime,size=918096k)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)
tmpfs on /dev/shm type tmpfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sda1 on /mnt/sda1 type ext4 (rw,relatime,data=ordered)
cgroup on /sys/fs/cgroup type tmpfs (rw,relatime,mode=755)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu type cgroup (rw,relatime,cpu)
cgroup on /sys/fs/cgroup/cpuacct type cgroup (rw,relatime,cpuacct)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,relatime,blkio)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,relatime,net_cls)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,relatime,perf_event)
cgroup on /sys/fs/cgroup/net_prio type cgroup (rw,relatime,net_prio)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,relatime,hugetlb)
/dev/sda1 on /mnt/sda1/var/lib/docker/aufs type ext4 (rw,relatime,data=ordered)
none on /mnt/sda1/var/lib/docker/aufs/mnt/137fb1ad9a432a3f4fa47667ecc9991c10149b71f02dfc06a8134fc348532a3d type aufs (rw,relatime,si=462e07a762a4065f,dio,dirperm1)
shm on /mnt/sda1/var/lib/docker/containers/137fb1ad9a432a3f4fa47667ecc9991c10149b71f02dfc06a8134fc348532a3d/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k)
mqueue on /mnt/sda1/var/lib/docker/containers/137fb1ad9a432a3f4fa47667ecc9991c10149b71f02dfc06a8134fc348532a3d/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
nsfs on /var/run/docker/netns/2e4dbeed7a66 type nsfs (rw)

My shared folders say in the UI that the folder path is /home

Upvotes: 17

Views: 2469

Answers (3)

Matt
Matt

Reputation: 74841

docker-machine does attempt to share the users directory between your machine running VirtualBox and the local default docker VM (like boot2docker did). If you are not running the default VM then create the vmshare and mount it yourself

On Windows C:\Users and on a mac /Users will be mounted in the default docker VM as /Users. Linux will share /home and mount as /home

vmhost$ docker-machine ssh default
vm$ mount | grep User
Users on /Users type vboxsf (rw,nodev,relatime)
vm$ exit

List a local users directory

vmhost$ ls -1 /Users/me/docker
compose_env_file
registry_push_test

Mount the local directory, which is shared to the vm, as a container volume.

vmhost$ docker run -v /Users/me/docker:/test busybox ls /test
compose_env_file
registry_push_test

The same works on the VM, as that is really where the above command is running.

vm$ docker run -v /Users/me/docker:/test busybox ls /test
compose_env_file
registry_push_test

If you want changes from your machine to appear in your VM, you have to work from your user directory and use relative paths in docker compose.

Upvotes: 0

pnovotnak
pnovotnak

Reputation: 4581

@AndyShinn's comment / @tianon's responses answer the question I believe.

However, if you are running an Ubuntu host, you might try running on bare metal, rather than in a VM. These days you can run docker containers as non-root via the --userns-remap flag, so you can be a little less concerned about security. You're in a unique position, because even though most tutorials and things list a docker-machine VM as a prerequisite, their target audience is mostly folks on OS X or Windows who cannot run docker without a VM. Don't loose sight of the trees for the forest--hypervisors (especially Virtualbox) == bad IO performance, excess memory usage, and slower startup. That's why we have docker :)

Upvotes: 1

tianon
tianon

Reputation: 1914

Unfortunately, your safest (and most compatible) bet is going to be to re-build the image and re-deploy the container for each change you make (ie, docker-compose build && docker-compose up -d or similar). This has the nice benefit of also working against remote Docker daemons (which as you explore docker-machine's features might become more tempting since they're so easy to use).

Upvotes: 2

Related Questions