Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 363
psychok7 Avatar asked Dec 05 '15 16:12

psychok7


People also ask

Where are docker volumes in Ubuntu?

Volumes are stored in a part of the host filesystem which is managed by Docker ( /var/lib/docker/volumes/ on Linux).

Does Docker compose create volumes?

We can also create a volume and then use it with a container using the -v flag. Docker-compose allows us to use volumes that are either existing or new.

What are the volumes in Docker compose?

In order to be able to save (persist) data and also to share data between containers, Docker came up with the concept of volumes. Quite simply, volumes are directories (or files) that are outside of the default Union File System and exist as normal directories and files on the host filesystem.


2 Answers

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

like image 197
tianon Avatar answered Oct 07 '22 23:10

tianon


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

like image 36
pnovotnak Avatar answered Oct 08 '22 01:10

pnovotnak