brikis98 / docker-osx-dev

A productive development environment with Docker on OS X
http://www.ybrikman.com/writing/2015/05/19/docker-osx-dev/
MIT License
1.43k stars 106 forks source link

Docker stays slow. Wrong shared directory? #108

Closed peterfication closed 9 years ago

peterfication commented 9 years ago

I tried to get docker-osx-dev to work but I had no success.

Dockerfile

FROM ruby:2.1.5

RUN apt-get update && apt-get install -y \
  build-essential \
  nodejs

ENV RAILS_ROOT /rails_root
RUN mkdir -p $RAILS_ROOT

COPY Gemfile $RAILS_ROOT/
COPY Gemfile.lock $RAILS_ROOT/

WORKDIR $RAILS_ROOT
RUN gem install bundler && bundle install --jobs 20 --retry 5

COPY . $RAILS_ROOT/

EXPOSE 3000
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

docker-compose.yml

web:
  build: .
  ports:
    - "3000:3000"
  volumes:
    - .:/rails_root
  links:
    - postgres_db:postgres
  environment:
    POSTGRES_URL: postgres://postgres-db:5432
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: secret

postgres_db:
  image: postgres
  hostname: postgres-db
  environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: secret

If I remove the volumes part in docker-compose.yml the server is fast as expected. If I don't remove it, the server is slow as expected. If I run docker-osx-dev all the sync stuff is happening. But the server stays slow.

I get the following debugging output:

2015-09-13 20:38:48 [INFO] Performing initial sync of paths: /Users/username/ruby/rails-project
2015-09-13 20:38:48 [DEBUG] Creating parent directories in Docker VM: sudo mkdir -p /Users/username/ruby && sudo chown -R docker /Users/username/ruby
2015-09-13 20:39:28 [DEBUG] Starting sync paths: /Users/username/ruby/rails-project

I thought, that docker-osx-dev is syncing the local dir with the dir specified in docker-compose.yml (/rails_root) or did I get something wrong?

If this behaviour is correct I don't know where to look for an error. Might anyone has a hint for me?

brikis98 commented 9 years ago

The confusion is that folders aren't synced directly from your host OS (OS X) to the Docker container. There is a middleman: the boot2docker VM, which runs linux. In other words, docker-osx-dev syncs each folder /foo/bar to the exact same location (/foo/bar) on the boot2docker VM. That VM, it turn, just uses the normal docker commands to mount that folder to some other path in the container.

Therefore, based on your docker-compose.yml file, if you're running docker-osx-dev in /Users/username/ruby/rails-project, it will sync the contents of the rails-project folder to /Users/username/ruby/rails-project on the boot2docker VM. That folder will then be mounted into /rails_root in the docker container.

If things are running slowly, one possibility is that you still have vboxsf shared folders enabled. Did you have boot2docker installed before you started using docker-osx-dev?

peterfication commented 9 years ago

Yes I installed it with the installer from the docker website. Then a new VM default was created. Then I installed docker-osx-dev which installed another VM boot2docker-vm.

Should I remove some stuff before installing docker-osx-dev?

peterfication commented 9 years ago

By the way, thanks for the explaining of the insides of docker-osx-dev!

brikis98 commented 9 years ago

Hm, the docker-osx-dev install command should, in theory, check if there are already vboxsf shared folders, and warn you in case there are. Perhaps there was a bug there.

If you have nothing important in your containers, you could try:

boot2docker down
boot2docker delete

Then just run docker-osx-dev again and it'll recreate the VM without shared folders, resync, and hopefully everything will be fast...

peterfication commented 9 years ago

Alright there was a shared folder. The whole /Users folder was shared in the boot2docker-vm VM. I don't know how this happened.

Thanks a lot for the hints!