Dockerize wordpress [英] Dockerize wordpress

查看:108
本文介绍了Dockerize wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试停放wordpress我想出这个场景:

Trying to dockerise wordpress I figure out this scenenario:

2个数据卷容器,一个用于数据库(bbdd),另一个用于wordpress文件(wordpress):

2 data volume containers, one for the database (bbdd) and another for wordpress files (wordpress):

sudo docker create -v /var/lib/mysql --name bbdd ubuntu:trusty /bin/true
sudo docker create -v /var/www/html --name wordpress ubuntu:trusty /bin/true

然后我需要一个容器用于mysql,所以我使用了从Docker集线器的官方mysql图像,还有来自第一个数据容器的卷/ var / lib / mysql:

Then I need a container for mysql so I use the official mysql image from docker hub and also the volume /var/lib/mysql from the first data container:

docker run --volumes-from bbdd --name mysql -e MYSQL_ROOT_PASSWORD="xxxx" -d mysql:5.6

然后我需要一个容器用于apache / php,所以我使用从docker hub的官方wordpress图像,还有卷/ var / lib / mysql从第一个数据容器:

Then I need a container for apache/php so I use official wordpress image from docker hub and also the volume /var/lib/mysql from the first data container:

docker run --volumes-from wordpress --name apache --link mysql:mysql -d -p 8080:80 wordpress:4.1.2-apache

我从Docker文档中了解到,如果我不删除数据容器,

如果我停止并删除正在运行的容器(apache和mysql)并使用最后的命令重新创建它们,则数据丢失:

What I understand from docker docs is that if I don't remove the data containers, I'll have persistance.
However if I stop and delete running containers (apache and mysql) and recreate them again with last commands, data get lost:

docker run --volumes-from bbdd --name mysql -e MYSQL_ROOT_PASSWORD="xxxx" -d mysql:5.6
docker run --volumes-from wordpress --name apache --link mysql:mysql -d -p 8080:80 wordpress:4.1.2-apache

但是,如果我创建没有数据容器的容器,似乎按照我的预期工作:

However if I create the containers without data containers, it seems to work as I expected:

docker run -v /home/juanda/project/mysql:/var/lib/mysql --name mysql -e MYSQL_ROOT_PASSWORD="juanda" -d mysql:5.6
docker run -v /home/juanda/project/wordpress:/var/www/html --name apache --link mysql:mysql -d -p 8080:80 wordpress:4.1.2-apache


推荐答案

您需要运行数据容器一次才能使其持续存在:

You need to run the data container for once to make it persistent:

sudo docker run -v /var/lib/mysql --name bbdd ubuntu:trusty /bin/true
sudo docker run -v /var/www/html --name wordpress ubuntu:trusty /bin/true

这是Docker的一个老bug,描述了此处。如果您的Docker版本较旧,您可能会受到影响。

This is an old bug of Docker described here. You may be affected if your Docker version is old.

这篇关于Dockerize wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆