Docker volume mapping sync files from guest to host

情到浓时终转凉″ 提交于 2020-01-06 06:34:08

问题


I created this basic Dockerfile expecting that test would become visible like html/test in host, but it didn't. I think because Docker creates an empty html dir in host and syncs that to guest. I tried with docker run and docker-compose, the results were the same.

The thing is, when I do the same actions with the WordPress image from Dockerhub, I see it creates a directory on host, neatly syncing all files from /var/www/html in guest. So now I wonder how I can create the same behaviour.

Dockerfile simple test:

FROM php:7.3.0-apache-stretch

RUN touch /var/www/html/test; \
    echo success > /var/www/html/test

VOLUME /var/www/html

docker-compose.yml simple test:

version: '3'

services:
  php:
    image: progonkpa/php-vol:1.0
    volumes:
      - ./html:/var/www/html
    restart: always

The thing is, when I do the same actions with the WordPress image from Dockerhub, I see it creates a directory on host, neatly syncing all files from /var/www/html in guest.

Dockerfile WordPress

docker-compose.yml using WordPress official image (progonkpa/wordpress:1.0 adds XDebug and other trivial files)

version: '3'

services:
   db:
     image: mysql:5.7
     volumes:
       - ./docker-mysql/db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: progonkpa/wordpress:1.0
     restart: always
     ports:
       - "80:80"
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
     restart: always
     volumes:
       - ./wordpress:/var/www/html
       - ./src:/var/www/src
       - ./vendor:/var/www/vendor

volumes:
    db_data:

来源:https://stackoverflow.com/questions/53801577/docker-volume-mapping-sync-files-from-guest-to-host

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!