17

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

Community
  • 1
  • 1
psychok7
  • 5,373
  • 9
  • 63
  • 101
  • Like the linked issue explains, host volume mounts are relative to the _host_ that is running Docker. If your Docker machine is running in a provider externally then the volume won't be the data from your local machine. Where is the Docker machine running? – Andy Shinn Dec 13 '15 at 18:48
  • I am running the docker machine in VirtualBox @AndyShinn – psychok7 Dec 14 '15 at 10:25
  • Can you log in to the VM (`docker-machine ssh `) and get the mounts (`mount`) and see if anything from the host is mounted in the VM? If not, then this won't be possible with a VM. You need to share the host folder with the VM in some way for the container to be able to access it. – Andy Shinn Dec 14 '15 at 18:37
  • @AndyShinn i dont think i have that shared host folder. but i will have a look and let you know – psychok7 Dec 15 '15 at 18:36
  • @AndyShinn i updated my question with the information i got from the mount when i ssh into the machine. it looks fine to me, do you see anything weird? – psychok7 Dec 16 '15 at 17:49
  • 2
    I don't see the `/home` mount in the VM from your host. So this would be why anything mounted from your host does not get mounted to the container. You are trying to go Host -> VM -> Container. Right now it is only mounting VM -> Container and the VM does not have the files (your project root). Does this make sense? Unfortunately, I don't really know how to troubleshoot or solve that issue as I haven't worked enough with boot2docker or docker-machine on Linux workstation. The `/home` folder might warrant a new question. – Andy Shinn Dec 17 '15 at 18:51
  • Can you enter the container with `docker-compose run web bash` and run the command from there? How does a `ls -la` look like? – schmunk Jan 04 '16 at 12:32

3 Answers3

2

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).

tianon
  • 1,866
  • 3
  • 22
  • 37
  • 1
    This doesnt look right.. It will be a pain to do this at every change when developing. Reminds me of C where you manually compile on each chance. Do you know if there are plans to change this behaviour in the future? – psychok7 Dec 18 '15 at 09:26
  • 1
    Well, with the application actually running inside a VM, we're essentially talking about remote bind mounts. I know Vagrant has a lot of connectors to help facilitate this kind of thing (I think it has everything from vboxsf to sshfs all the way to just using rsync back and forth) that are probably worth checking out. It's also probably worth trying NFS instead (especially since your host is Linux too). – tianon Dec 18 '15 at 23:18
1

@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 :)

pnovotnak
  • 4,341
  • 2
  • 27
  • 38
  • i get the thing about "being better to run it in my host if i use linux" but what doesn't make sense to me is how do OS X and windows users deal with "this problem". Why advertise docker machine as a subsitute or improvement over how we did before (even on linuxs hosts) if you can't simply update your code on save without having to build it again? Do OS X users build everytime they make a small code change? – psychok7 Feb 22 '16 at 11:03
  • Personally, I do actually rebuild every time I run new code. Usually, unless there is weird scientific software that is part of the codebase that won't run on OS X... I'm running I work 100% on my local OSX machine, then pack a container when I'm satisfied and my tests pass. If you want to run in a container on a VM (locally or otherwise.) You'll need to share your work directory with your VM so that it may then share it with the container. The process is similar with remote VMs, except that you'd use sshfs, nfs, or some other network protocol to synchronize the files over the network – pnovotnak Feb 23 '16 at 06:13
0

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.

Matt
  • 68,711
  • 7
  • 155
  • 158