php - How to initialize a named volume shared across several containers with docker-compose -


i'm trying build own wordpress-nginx-php_fpm stack docker-compose face problem named-volume , initialization.

here docker-compose.yml:

version: '2' services:    db: #https://hub.docker.com/_/mysql/     image: mysql                                                                            restart:     volumes:       - "wp-db:/var/lib/mysql:rw"       - env_file:       - "./conf/db/mysql.env"     networks:       -                                                                              nginx: #https://hub.docker.com/_/nginx/     image: nginx     restart:     volumes:       - "wp-files:/usr/share/nginx/html"       - "./conf/nginx:/nginx:ro"       - "./conf/tools:/tools:ro"     networks:       - front       -     ports:       - "8080:80"     environment:       - "php_fpm_host=php-wp:9000"       - "php_fpm_root_dir=/var/www/html"     command: "bash /tools/wait-for-it.sh php-wp:9000 -t 30 -- bash /tools/detemplatize-it.sh /nginx/nginx.template:/nginx.conf -- nginx -c /nginx.conf"    php-wp: #https://hub.docker.com/_/wordpress/     image: "wordpress:fpm"     restart:     volumes:       - "wp-files:/var/www/html"       - "./conf/tools:/tools:ro"     env_file:       - "conf/wp/wordpress.env"     networks:       -     command: "bash /tools/wait-for-it.sh db:3306 -t 30 -- php-fpm -f"  networks:   front: {}   back: {}  volumes:   wp-files: {}   wp-db: {} 

as can see, have 2 named volumes. no problem "wp-db" because it's used "db" service.

my problem "wp-files" volume, mounted in 2 services(=containers)

  • which service copy data named volume first ?
  • does second container overwrite data put first 1 ?
  • how "initialize" named volume somewhere , use (after) 2 containers mounted ? heard "nocopy" flag.
  • am obliged use other stuff (like data container) instead of named volume ?

thank you. note: (everything on same physical host)

here find answer:

which service copy data named volume first ?

the container starts first (thanks volumes-from, depends-on, ...)

does second container overwrite data put first one?

no, once named volume has been "initialized" (means no empty anymore), overwrite every mount point 's attached to.

how "initialize" named volume somewhere , use (after) 2 containers mounted ? heard "nocopy" flag.

there indeed "nocopy" flag, in "docker run" documentation, doesn't seem work other flag ("ro" or "rw").

am obliged use other stuff (like data container) instead of named volume ?

therefore, no.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -