I am new to docker, I am on Mac OS with a MacBook and would like to setup Wordpress with its mysql database all on one container. then I would like to save the container ( after I do some modifications on Wordpress ) and then load it with the running version to another computer - my boss computer
how can I do that with simple steps to understand it in the future !
The current situation is that I have my running container with Wordpress on my pc and finished my work on it
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wordpress latest 7b8a178c0ebe 8 days ago 554MB
mysql 5.7 f26e21ddd20d 2 weeks ago 450MB
mysql latest 667ee8fb158e 2 weeks ago 521MB
I tried to save the Wordpress container with docker save container.tar then load it on the other pc but this is just getting as if am installing a fresh Wordpress copy
thanks in advance
CodePudding user response:
This is not how to use docker.
Better is to split every process to a microservice, means 1 container for wordpress and 1 container for the mysql database.
You can use docker-compose
with a yml file to build that containers.
Here you find how to do that, next time use a search engine.
If you wan't to build a new image of a running container, with your new settings do this:
- run your images
- exec into running container's with bash or sh
- do your settings
- exit exec container
- create a new image of the running container with docker run commit Create Image from running container:
$ docker commit [RUNNING_CONTAINER_ID] [MY_NEW_IMAGE_NAME]
$ docker commit alpine1 alpine:v1
- stop the container and delete it(or not)
- run or build again your new image, with your modified settings
You can export your image to a tar file and copy to next machine you need with:
Image, save one or more images to a tar archive
$ docker save busybox > busybox.tar
Image, load an image from a tar archive or STDIN
$ docker load < busybox.tar
Edit:
You can use volumes and backup them too.
Back up a volume | Restore volume from backup
CodePudding user response:
Installing two different services on the same container is far from the suggested docker usage, the best way is to have two containers, one for wordpress and one for the database.
After that, you can, for instance, use a docker-compose file to make them "work together".
Edit:
Of course if you took another computer and started from the official images, you would obtain a fresh wordpress and not the modified one.
For that my suggestion is to create two different images, one that derives from the wordpress one and that has your changes, while the other one that derives from the mysql one and contains your changes.
A way to create an image could be this.
Also, for mysql, since you are not changing any code, I think a good way would be to create a "host" docker volume for the mysql data. That way, you will just copy-paste the folder in the pc of your boss.
If instead you really want to have just one image, either you write a Dockerfile starting from the mysql image and add wordpress and your changes with code, or you do this things with interactive access in a mysql container and you transform the container into an image