简体   繁体   中英

Wordpress - cannot change username or password in docker-compose

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: foo@mydomain.com
   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:

  • new build
    1. remove the data (or maybe image)
    2. modify docker-compose.yml file with new password
    3. running docker-compose again
  • manually change the password, etc
    1. run the database container
    2. login to the container eg docker exec -it <CONTAINER-ID> /bin/bash
    3. change the password, etc
    4. logout and commit this new change

and it is obvious that new build is simpler and better option to do.

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