How to update wp-config file in Docker

I am trying to change our blogs from Wordpress to inside a docker container, so that we can move around it easily. I wrote a docker-compose file for the purpose and it ran smoothly the first time. But I made some mistakes on configs and missed to write the HOME and SITEURL on the docker-compose file in the beginning. Now, I can't seem to change the wp-config.php. according to Wordpress, it can't be updated from the entrypoint script once it's already been written. I tried a bunch of other scenarios:

  1. I tried to use docker exec command to update the wp-config.php file. bash does not have vim/nano there.

  2. I deleted all the containers and volumes and images, but still, it doesn't change anything. I downed and re-uploaded the compose file many times, but nothing is changing.

Here's a snippet of my compose file. What should I do now? [I need to change the home and siteurl because the Wordpress will be served from a different server.]

version: '3'

services:
  db:
    image: mysql:8.0
    container_name: db
    restart: unless-stopped
    env_file: .env
    environment:
      - MYSQL_DATABASE=wordpress
    volumes:
      - mysql_db_data:/var/lib/mysql
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - app-network

  wordpress:
    depends_on:
      - db
    image: wordpress:5.1.1-fpm-alpine
    container_name: wordpress
    restart: unless-stopped
    env_file: .env
    environment:
      - WORDPRESS_DB_HOST=db:3306
      - WORDPRESS_DB_USER=$MYSQL_USER
      - WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
      - WORDPRESS_DB_NAME=wordpress
      - WORDPRESS_CONFIG_EXTRA=
          define('WP_HOME','http://dev.insurance.kothay.com/');
          define('WP_SITEURL','http://dev.insurance.kothay.com/');
    volumes:
      - wordpress_data:/var/www/html
    networks:
      - app-network
  
  webserver:
    depends_on:
      - wordpress
    image: nginx:1.15.12-alpine
    container_name: webserver
    restart: unless-stopped
    ports:
      - 8080:80
    volumes:
      - wordpress_data:/var/www/html
      - ./nginx-conf:/etc/nginx/conf.d
    networks:
      - app-network
  
volumes:
  wordpress_data:
  mysql_db_data:
  
networks:
  app-network:
    driver: bridge

Docker message:

wordpress    | WARNING: environment variable WORDPRESS_CONFIG_EXTRA is set, but wp-config.php already exists
wordpress    |   The contents of this variable will _not_ be inserted into the existing wp-config.php file.
wordpress    |   (see https://github.com/docker-library/wordpress/issues/333 for more details)
w

Let me know what I can do. Thanks in advance.

Topic docker php Wordpress

Category Web


The Solution that finally worked was to turn down the containers using docker-compose down command. I was not detaching the containers, but I still need to turn them down. Once I did so, I then run the command docker volume ls to list all the volume and delete the one with Wordpress data in it by docker volume rm <volume_name>.

For Wordpress, since wp-config file cannot be changed after initial edit, I guess this is A solution but it's not the only solution. I am running a relatively small blogging server and most of the data will always be on backup. Hence this up-down will not be that big of a deal, if I need to change any Wordpress settings or update the wp-config file.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.