简体   繁体   中英

Fail to connect mysql in running wordpress docker

I used the script to start mysql and wordpress through docker. ( https://github.com/lamuguo/wordpress-setup/blob/master/start_wordpress.sh )

The xfguo-wp image is built based on docker official wordpress 4.3.1 repository: https://github.com/docker-library/wordpress/commit/4823a04099579f2aafb118ae8177449425cc84d2

Command to build the image: (under apache directory) ~/github/wordpress/apache$ docker build -t xfguo-wp .

However, I can't connect to mysql DB successfully, error below by "docker logs techmeetup-wordpress"

... WordPress not found in /var/www/html - copying now... Complete! WordPress has been successfully copied to /var/www/html

MySQL Connection Error: (2002) Connection refused

Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10

Any thoughts? Feel free to comment in the code of my wordpress-setup repository.

Thanks!

Your shell script doesn't wait for the mysql container to initialise.

Try putting

sleep 10 

in your shell script (start_wordpress.sh) after starting mysql and before starting wordpress. This will introduce a delay of 10 seconds before running the wordpress container, allowing it to connect to mysql.

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