Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

To replace the volumes_from: directive from version 2 (for helpyio), 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

like image 937
Thomas_Lydra Avatar asked Aug 13 '26 14:08

Thomas_Lydra


1 Answers

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
like image 112
larsks Avatar answered Aug 16 '26 21:08

larsks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!