Docker volume mapping sync files from guest to hos

2019-08-28 00:36发布

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:

0条回答
登录 后发表回答