简体   繁体   中英

docker-compose : absolute path for shared volumes in version 3

To replace the volumes_from: directive from version 2 (forhelpyio ), I tried this, but something went wrong.

version: "3"

services:
  frontend:
    ...
    volumes:
      - myVolume:/var/www:ro
  backend:
    ...
    volumes:
      - myVolume:/var/www

volumes:
  myVolume:
    driver:      local
    driver_opts:
      type:      none
      device:    "/my/local/absolute/path/"
      o:         bind

I have errors like

ERROR: for frontend: Cannot create container for service frontend: failed to mount local volume: mount /my/local/absolute/path/:/var/www, flags: 0x1000: no such file or directory

I also tried some variant in volumes: options but without success. And last thing, I don't want to create manually this local directory.

I am sure to miss something, but can't see what... Has anyone a solution for this use case?

Many thanks

There's no reason to make your docker-compose.yml that complicated. You can simply do this:

version: "3"

services:
  frontend:
    ...
    volumes:
      - /my/local/absolute/path/:/var/www:ro
  backend:
    ...
    volumes:
      - /my/local/absolute/path/:/var/www
  1. make custom directory:
sudo mkdir /static
  1. and edit file docker-compose.yml
version: "3.9"
services:
  web:
    volumes:
      - "static_volume:/app/media"

volumes:
  static_volume:
    driver: local
    driver_opts:
      type: volume
      o: bind
      device: /static
        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM