Reputation: 4356
This is my Docker Compose file:
version: '2'
services:
wordpress:
image: wordpress
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: *****
WORDPRESS_DB_NAME: wordpress
links:
- db:mysql
ports:
- 8000:80
#network_mode: "none"
restart: always
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: *****
MYSQL_DATABASE: wordpress
MYSQL_USER: root
MYSQL_PASSWORD: *****
ports:
- 8001:3306
volumes:
- ./configs/etc/mysql/my.cnf:/etc/mysql/my.cnf
restart: always
And this is the error I got in docker logs:
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10
Line 10 is the "links" one.
I also got a 502 Bad Gateway error on the front page ( I installed Nginx as a proxy in my host os to forward port 80 to 8000)
Note that the nginx proxy access logs are all returned as a 302 not 502.
Ps: I am using the official Docker images
Upvotes: 1
Views: 1043
Reputation: 753
You don't need to open MariaDB port publicly, just expose port 3306 to other containers.
So in db replace:
ports:
- 8001:3306
with:
expose:
- "3306"
I believe that default database port in Wordpress is 3306, which is also default port in MariaDB.
Upvotes: 0