Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress wp-config.php doesn't update in Dockers?

I am using Wordpress and docker container. The problem is that I updated the wp-config.php file but everything looks the same. I have something like this:

CONTAINER ID        IMAGE                   NAMES
b2711d4b72a1        phpmyadmin/phpmyadmin   website_phpmyadmin_1
8a89ee46d673        wordpress:4.7.5         website_wordpress_1
2a167667f705        mysql:5.7               website_db_1

My docker-compose.yaml looks like this:

version: '2'
services:
wordpress:
depends_on:
  - db
image: wordpress:4.7.5
restart: always
volumes:
  - ./wp-content:/var/www/html/wp-content 
environment:
  WORDPRESS_DB_HOST: db:3306
  WORDPRESS_DB_PASSWORD: p4ssw0rd!
ports:
  - 80:80
  - 443:443
networks:
  - back
  db:
    image: mysql:5.7
    restart: always
    volumes:
       - db_data:/var/lib/mysql
    environment:
  MYSQL_ROOT_PASSWORD: p4ssw0rd!
networks:
  - back
  phpmyadmin:
    depends_on:
       - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - 8080:80
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: p4ssw0rd!
        networks:
      - back
     networks:
       back:
      volumes:
  db_data:

I have run docker-compose up, build and down but everything is the same.

like image 516
jfk83 Avatar asked Aug 08 '17 06:08

jfk83


2 Answers

The official WordPress docker image will automatically configure wp-config.php using the environment variables you set [documentation].

If there are any variables such as WORDPRESS_DB_HOST, WORDPRESS_DB_PASSWORD, etc., they will be used to build a wp-config.php file upon container creation.

If you want to provide a custom wp-config.php file, you need to make sure there are no related environment variables, and create a volume mapping for your modified file, like so:

version: '2'
...
volumes:
  - ./wp-content:/var/www/html/wp-content 
  - ./wp-config.php:/var/www/html/wp-config.php
...

On docker-compose up, Docker will load your custom wp-config.php into the container and then run the WordPress image's docker-entrypoint.sh which updates the file with the values set in your environment variables.

like image 194
Taylor Hx Avatar answered Sep 19 '22 11:09

Taylor Hx


You can make use of the WORDPRESS_CONFIG_EXTRA environment variable to define any other config values in the wp-config.php file.

As an example:

WORDPRESS_CONFIG_EXTRA: |
  define('WP_ALLOW_MULTISITE', true );
  define('MULTISITE', true);
  define('SUBDOMAIN_INSTALL', false);
like image 36
jpunk11 Avatar answered Sep 21 '22 11:09

jpunk11