I have an already running MySQL container that I use for several other containers.
Now I'm trying to connect a wordpress container to it but I'm getting:
Error establishing a database connection
And the wp container log shows:
MySQL Connection Error: (1045) Access denied for user 'my_user'@'172.20.0.5' (using password: YES)
The mysql container is already up and running and the container's name is mysql
, and I use a PHPMyAdmin container to manage it; I'm able to do so just fine (it's connected to the Mysql server container).
Here's my docker compose code for the WP container:
version: '2'
services:
wordpress:
image: wordpress:latest
restart: unless-stopped
ports:
- 80
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_USER: "my_user"
WORDPRESS_DB_PASSWORD: "12345"
WORDPRESS_DB_NAME: "my_user"
volumes:
- /f/Sites/mia:/var/www/html
networks:
- occms
- ocdb
networks:
occms:
external:
name: oly-cms
ocdb:
external:
name: oly-db
Notes:
my_user
my_user
, and gave it full permissions to the my_user
db. (note that the actual user and db start with a "g"; I've changed them to "my_user" for privacy in this question.) WORDPRESS_DB_HOST:
variable and restart the wp container, i do see it's value reflected in the wp-config.php
file.wp-config.php
I have made sure the credentials match:define('DB_NAME', 'my_user');
/** MySQL database username */
define('DB_USER', 'my_user');
/** MySQL database password. Changed on: 3/20/2014 2:40 PM */
define('DB_PASSWORD', '12345');
/** MySQL hostname */
define('DB_HOST', 'mysql');
I was under the assumption that as long as I have both the mysql and wp containers in the same docker network, they should be able to connect to each other? Am I missing something in the WP compose code?
You set the variable for wordpress, not for MySQL, so this won't work.
I wrote a docker-compose
to load a wordpress with my mysql:
docker-compose up -d
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.