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

named volumes in docker-compose.yml should not be synced #168

Closed ComaVN closed 7 years ago

ComaVN commented 8 years ago

When defining named volumes in docker-compose.yml, docker-osx-dev assumes them to be relative paths:

myapp:
    build: .
    volumes:
        - /Users/foo/myabsolutepath:/myapp/absolute
        - mynamedvolume:/myapp/named

Result:

% docker-osx-dev -s .
2016-01-29 10:15:28 [INFO] Using sync paths from command line args: .
2016-01-29 10:15:28 [INFO] Using sync paths from Docker Compose file at docker-compose.yml: /Users/foo/myabsolutepath mynamedvolume
2016-01-29 10:15:28 [INFO] Complete list of paths to sync: /Users/foo/ /Users/foo/myabsolutepath /Users/foo/mynamedvolume
2016-01-29 10:15:28 [INFO] Using excludes from ignore file .dockerignore: .git vendor
2016-01-29 10:15:28 [INFO] Complete list of paths to exclude: .git vendor
2016-01-29 10:15:28 [INFO] Complete list of paths to include:
2016-01-29 10:15:28 [INFO] Starting docker-osx-dev file syncing
2016-01-29 10:15:28 [INFO] Installing rsync in the Docker Host image
2016-01-29 10:15:29 [INFO] Performing initial sync of paths: /Users/foo /Users/foo/myabsolutepath /Users/foo/mynamedvolume
2016-01-29 10:15:29 [INFO] Initial sync using tar for /Users/foo/myabsolutepath
2016-01-29 10:15:29 [INFO] Initial sync using tar for /Users/foo/mynamedvolume
tar: mynamedvolume: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors.
2016-01-29 10:15:30 [INFO] Initial sync done
2016-01-29 10:15:30 [INFO] Watching: /Users/foo /Users/foo/myabsolutepath /Users/foo/mynamedvolume

I did not expect mynamedvolume to be synced

brikis98 commented 8 years ago

I didn't know that was even supported. I thought you used the volumes_from entry for that? Or is this something new?

ComaVN commented 8 years ago

Seems like it's been available for a while: https://github.com/docker/compose/issues/1823

Darep commented 8 years ago

Yeah, named volumes are the unofficially/officially (https://github.com/docker/docker/issues/17798) recommended alternative to data-only containers since Docker 1.9.0. We recently switched to them and noticed this as well :)

The named volumes need to be declared in the docker-compose.yml file like this:

version: '2'
volumes:
  data:
  gems:
services:
  rails:
    build: .
    command: bundle exec rails s
    ports:
      - "3000:3000"
    links:
      - redis
    volumes:
      - gems:/gems
  redis:
    image: redis
    volumes:
      - data:/data

Reference: https://docs.docker.com/compose/compose-file/#volumes-volume-driver

One approach would be to parse the names under the top-level volumes: key and then just not ignore those later when parsing volumes-lines under the service.

ain commented 7 years ago

Reproduced as well, it really is a problem.

volumes:
  ugc: {}
2016-08-23 14:40:58 [INFO] Initial sync using tar for /Users/ain/projects/.../ugc
tar: ugc: Cannot stat: No such file or directory
tar: Error exit delayed from previous errors.
brikis98 commented 7 years ago

This should have been fixed by #197.