Reputation: 567
I have found this, but it does not work for me.
My (really) simple docker-compose.yml
:
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
Starting:
docker-compose up
After made some change to containers (install plugins and themes on wordpress).
docker-compose stop
docker commit main_mysql_1 test-mysql
docker commit main_wordpress_1 test-wordpress
docker save test-mysql > test-mysql.tar
docker save test-wordpress > test-wordpress.tar
Save the two tar files on another machine and load them:
docker load -i ./test-mysql.tar
docker load -i ./test-wordpress.tar
Now change the docker-compose.yml
to:
version: '3.1'
services:
wordpress:
image: test-wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
mysql:
image: test-mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
But the container started is wordpress from scratch. Nothing of work done (plugin, themes, etc) was preserved.
What is my mistake? I don't want to use online repository for these private purposes.. Could you suggest a more simple and powerful procedure for pass container between two hosts?
A workaround with volumes:
version: '3.1'
services:
wordpress:
container_name: GREB_wordpress
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_PASSWORD: example
volumes:
- ./www:/var/www/html
mysql:
container_name: GREB_mysql
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- ./mysql_data:/var/lib/mysql
Upvotes: 15
Views: 20720
Reputation: 567
First of all, docker volumes are not part of an image and/or a container. So these should be saved further the docker images (docker save
).
For a better understanding of docker file system, volumes, ro/rw layer, could be read http://container-solutions.com/understanding-volumes-docker/.
Figure out if our image use volumes (seek "Volumes" key):
docker inspect image_name
You have different advantage to use volumes (refer to docker documentation for well understand) such as I/O performance.
A the end, for backup volumes:
tar -cvzPf volume_name_backup.tar.gz /var/lib/docker/volumes/VOLUME_NAME
...and restore them in the same placedocker exec mysql_container /usr/bin/mysqldump -u root --password=root --all-databases > mysql_dump_backup.sql
Upvotes: 10