Let's use this docker-compose.yml:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- ./mysql:/var/lib/mysql # <- important
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./wp:/var/www/html # <- important
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
I noticed that:
When doing
mkdir wp docker-compose up # create a basic Wordpress website from the browser # stop the containers from the command-line with CTRL+Cthen,
./wp/(initially empty) is filled with the new Wordpress files (**). This is normal.Then let's do
docker rm wordpress_1 db_1 # remove the existing containers but keep # ./wp/ as it has been created in the previous step (**) docker-compose upDuring the re-creation of the containers,
./wp/is not overwritten with new Wordpress files, instead the previous files from previous step (**) are kept! Why?How does it magically know that new Wordpress files should not be written, but that instead, the previous files should be kept?
Question: How does docker decide if /hostdir/:/containerdir/ listed in volumes: should override the files which are already present in the original docker image, or not?