简体   繁体   中英

How to install wordpress by docker?

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:

  1. Suggest follow docker official guide if you want to install WP by docker.

  2. If you want to mapping the mysql and wordpress, can add follow config in compose:

    在此处输入图片说明

  3. 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:

    在此处输入图片说明

  4. 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.

  5. 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”.

  6. If you want to debug wordpress/mysql and check log, you can not add “-d”, use this “docker-compose up”

  7. 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/

    在此处输入图片说明

  8. If you want to add some software in docker of Wordpress, eg: 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.

There is a very detailed explanation in the official docker docs to how to do this. Follow the link below, and you shall get wordpress up and running.

https://docs.docker.com/compose/wordpress/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM