6

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

esprit libre
  • 61
  • 1
  • 4
  • 1
    Can you `COPY` the same tree into both images in their respective Dockerfiles? I'd try to avoid sharing file content between containers this way. – David Maze Nov 26 '19 at 16:09
  • I'd try to avoid sharing file content between containers too. Docker comes up with idea that we will separate out apps/services so make it tightly couple might not be a best practice. In this case if the static files created by the code then I think just create a Dockerfile to build or collect the static files for your frontend service is better. And for sure, another Dockerfile is for your backend service. – Toan Quoc Ho Nov 26 '19 at 17:09
  • Hello. larsks advice was good. too fast on testing. I agree sharing is not recommended but it is asked in docker-compose I try to adapt ([helpyio](https://github.com/helpyio/helpy/blob/master/docker-compose.yml)). – esprit libre Nov 28 '19 at 15:02

2 Answers2

3

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
larsks
  • 277,717
  • 41
  • 399
  • 399
  • I first tried this, but I get an error and then mistake myself. I clean everything well (`docker system prune -a`, `docker volume rm ...`) and relaunch and it works now. Thanks for make me re-test basics! – esprit libre Nov 28 '19 at 15:00
-1
  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