If I use this inside docker-compose, it works fine:
db_node_domain:
image: mysql:5.7
volumes:
- ./db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: mystrongpassword
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
container_name: wp_db
networks:
- "proxy-tier"
wordpress:
depends_on:
- db_node_domain
image: wordpress:latest
ports:
- "8080:80"
expose:
- "8080"
restart: always
environment:
VIRTUAL_HOST: blog.mydomain.com
LETSENCRYPT_HOST: blog.mydomain.com
LETSENCRYPT_EMAIL: [email protected]
WORDPRESS_DB_HOST: db_node_domain:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
container_name: wordpress
networks:
- "proxy-tier"
I want to use different username and stronger passwords for MYSQL_USER
and WORDPRESS_DB_USER
but if I make any changes at all in them I get 502 Bad Gateway from nginx. Can I not change these?
it is because you have already built the database.
When you have run the docker-compose up
for the fist time, these values have been set:
environment:
MYSQL_ROOT_PASSWORD: mystrongpassword
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
and this part:
volumes:
- ./db_data:/var/lib/mysql
means it is a persistence data and after stopping the container, for the next run, the data will be available and new ones will not be set. So you have two options:
docker-compose.yml
file with new passworddocker-compose
againdocker exec -it <CONTAINER-ID> /bin/bash
and it is obvious that new build is simpler and better option to do.