Question:
I follow some guides to install the wordpress + mysql by docker, but found that not work... I tried to test by curl command, found no any output, I need your help for the issue... (I just transfer my wordpress hosting to VPS)
docker run --name mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql
docker run --name wordpress --link mysql:mysql -e WORDPRESS_DB_PASSWORD=123456 -d wordpress:4.8.2-apache
[root@vps ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6bd3954390e0 wordpress:4.8.2-apache "docker-entrypoint..." 11 seconds ago Up 10 seconds 80/tcp wordpress
eaa1f6a2fb96 mysql "docker-entrypoint..." 25 seconds ago Up 24 seconds 3306/tcp mysql
Follow troubleshooting and test wordpress:
[root@vps ~]# curl localhost:80
curl: (7) Failed connect to localhost:80; Connection refused
[root@vps ~]# docker inspect --format='{{.NetworkSettings.IPAddress}}' 6bd3954390e0
172.17.0.3
[root@vps ~]# curl 172.17.0.3:80
[root@vps ~]#
Resolved:
Thanks @junius(who in docker forums), @VladoDemcak, @yamenk and @user4860092! The issue was resolved!
If I do “docker run xxxx” that should not work for me, that maybe was caused by command incorrect. Then I tried to do docker-compose, curl no any output, but Wordpress should work normal. So curl no any output should normal.
Now, I completed task that transfer my Wordpress to new VPS, share follow tips and experiences:
Suggest follow docker official guide if you want to install WP by docker.
If you want to mapping the mysql and wordpress, can add follow config in compose:
If you not config port part in compose, that mean not expose any port to outside of container, so you couldn't access the port from outside, as follow:
When you change “docker-compose.yml”, please not only use “docker-compose down” that will not delete all config/file, suggest you do “docker-compose down --volumes” that as install guide.
If you change database name, please add “WORDPRESS_DB_NAME: xxx” in environment part of Wordpress(docker-compose.yml), that should no this config in official install guide. So wordpress default connect database name is “wordpress”.
If you want to debug wordpress/mysql and check log, you can not add “-d”, use this “docker-compose up”
In order to restore mysql database, you can install phpmyadmin by docker, then add follow config to “docker-compose.yml”, and follow guide by “https://hub.docker.com/r/phpmyadmin/phpmyadmin/”
If you want to add some software in docker of Wordpress, e.g: zip, mailx, you can do follow:
You don't have exposed ports, so you are not able to access wordpress (from host) which is running on the port 80
in docker container.
Probably you will need to expose port to some other port (not 80). So try to change docker run command for wordpress as follows:
docker run --name wordpress --link mysql:mysql -e WORDPRESS_DB_PASSWORD=123456 -p 81:80 -d wordpress:4.8.2-apache
Please notice -p 81:80
parameter in the command - Docker documentation expose-incoming-ports.
After that wordpress should be available on localhost:81
.
I would suggest you to create docker-compose
for your services rather than maintain linking and with docker-compose
you are also able to run both services with one command.