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

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.

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.

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);

The trick:
wp:
image: wordpress:latest
ports:
- 80:80
volumes:
- ./wp-content:/var/www/html/wp-content
- ./wp-config.php:/usr/src/wordpress/wp-config-sample.php
When local wp-config.php changes you should delete /var/www/html/wp-config.php from container, docker will copy it again... but it works!

Related

docker-compose with wp-cli and custom theme wrong permission

I have the docker-compose file at the end of the post
In this file I create a volume to link the custom theme folder.
When I try to run a wp-cli command in a CONTAINER - CLI I have a permission problem because the folder wp-content is owned by root and the container is run as user xfs.
In the CONTAINER - WORDPRESS we can see that the wp-content folder is also owned by root.
CONTAINER - WORDPRESS
CONTAINER - CLI
But when I unlink my custom theme folders this issue no longer happens.
it is possible to see in the CONTAINER - CLI that the owner of the wp-content folder is xfs as it is correct, as well as in the WORDPRESS - CONTAINER the wp-content folder also belongs to the user www-data as it should be.
CONTAINER - WORDPRESS
CONTAINER - CLI
This is mine docker-compose.yml
version: "3.9"
services:
wordpress:
image: wordpress:5.2.1-php7.3
environment:
WORDPRESS_DB_HOST: database:3306
WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
WORDPRESS_DB_USER: ${MYSQL_USER}
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
WORDPRESS_TABLE_PREFIX: ${WORDPRESS_TABLE_PREFIX}
WORDPRESS_DEBUG: ${WORDPRESS_DEBUG:-false}
env_file: .env
restart: always
volumes:
- ./wp:/var/www/html # Full wordpress project
- ./theme:/var/www/html/wp-content/themes/custom-theme # Theme development
ports:
- ${WORDPRESS_PORT}:80
depends_on:
- database
cli:
image: wordpress:cli-2.3.0
env_file: .env
user: xfs
depends_on:
- database
- wordpress
volumes:
- ./wp:/var/www/html
database:
image: mariadb:10.5.9
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
restart: always
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u root --password=${MYSQL_PASSWORD}
interval: 5s
retries: 5
manage:
image: phpmyadmin:5
environment:
PMA_HOST: database
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
ports:
- ${MANAGE_PORT}:80
restart: always
depends_on:
database:
condition: service_healthy
volumes:
db_data:
wp_data:
I found on this answer here on StackOverflow that you need to add ./wp-content/:/var/www/html/wp-content/ to the volumes, because:
Docker defaults any named volumes to root, so by binding it dropped the root owner.

Docker volumes that share the same parent?

I'm trying to build a docker based WordPress development environment and I want to be able to have a folder structure like this:
.
|
--wp-data
|
--wp-content
|
--plugins
|
--themes
where plugins and themes are also inside wp-content
this is my docker-compose file:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- ./wp-data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- '8000:80'
restart: always
volumes:
- ./wp-content:/var/www/html/wp-content/
- ./themes:/var/www/html/wp-content/themes/
- ./plugins:/var/www/html/wp-content/plugins/
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
wp-data:
wp-content:
themes:
plugins:
the wp-data and w-content are created ok
but the nested themes and plugins arent
what im missing?
Regards
You are misusing volumes. In your docker-compose.yml you create bind mounts for each service - that means you mount a particular directory of the host into containers.
At the same time you are declaring a section volumes where explicitly declare volumes with the same names, but they are never used and created as empty directories.
Of you want to create and use volumes, you need to rewrite your docker-compose.yml in the following manner:
services:
...
db:
...
volumes:
- wp-data:/var/lib/mysql
...
wordpress:
volumes:
- wp-content:/var/www/html/wp-content/
- themes:/var/www/html/wp-content/themes/
- plugins:/var/www/html/wp-content/plugins/
volumes:
wp-data:
wp-content:
themes:
plugins:
This will enable volumes, but you still need a way to put data from host into them (like docker cp for example).
From the other hand, of you intended to use bind mounts, you need to completely remove ending volumes: section not to get confused.

Restore a WordPress site on Docker.

I have a website which i want to containerised i tried following the steps mentioned on this link
i have my files copied to /var/www/html/example.com/src/ and also my docker-compose file looks like this :
version: '2'
services:
example_db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: ${WP_DB_USER_PASSWORD}
MYSQL_DATABASE: ${WP_DB_NAME}
volumes:
- /var/lib/mysql:/docker-entrypoint-initdb.d/example.sql
container_name: example_db
restart: always
example:
depends_on:
- example_db
image: wordpress:5.0.0-php5.6-apache # we're using the image with php7.1
environment:
WORDPRESS_DB_PASSWORD: ${WP_DB_USER_PASSWORD}
WORDPRESS_DB_NAME: ${WP_DB_NAME}
container_name: example
ports:
- "1512:80"
restart: always
links:
- example_db:mysql
volumes:
- ./src:/var/www/html/docker/example.com/src/
i have my wordpress file in /www/html/docker/example.com/src/ and the db backup inside /src/docker/example.com/data/docker-entrypoint-initdb.d/lbdocker.sql
every time i acces the website it goes to the WordPress setup guide.
this is old but the issue is related to the $table_prefix
Your backup table prefix is different than the destination.
Update your config and it will work.
Fix

Docker Compose WordPress Volumes Appear Empty

I'm trying to set up a simple WordPress build using docker compose. However, when I build it, the volumes appear to be empty.
Here is my docker-compose.yml:
version: '3'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8000:80
volumes:
- ./development:/var/www/html
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: password
depends_on:
- db
networks:
- wordpress-network
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- 8080:80
links:
- db:db
db:
image: mariadb:latest
ports:
- 127.0.0.1:3306:3306
command: [
'--default_authentication_plugin=mysql_native_password',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci'
]
volumes:
- wp-data:/var/lib/mysql
environment:
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: password
networks:
- wordpress-network
networks:
wordpress-network:
driver: bridge
volumes:
wp-data:
driver: local
Here is my local project structure, with theme stylesheet:
I run docker-compose to build the image:
docker-compose up -d --build
But when I open the build in my browser, it looks like the theme is empty:
This leads me to believe the volume is empty. I'd appreciate any help or insights into this issue, thank you.
In your docker-compose file you say ./wp-data:/var/lib/mysql which is host folder mapping (not volume) but in your docker-compose you define docker named volume called wp-data and if you want to use this volume you have to use it as wp-data:/var/lib/mysql. I would also suggest to remove ${PWD} because it might cause problem in sh

Using composer with wordpress in docker

I'm try to setup a docker workspace with Alpine, PHP, Apache, MySQL and Composer.
Currently I'm trying to use the following images:
PHP, Alpine and Composer: https://hub.docker.com/r/petehouston/docker-alpine-php-composer/
Wordpress: https://hub.docker.com/_/wordpress/
I created a docker-compose.yml file to manage this dependencies for me.
docker-compose.yml
version: '2'
services:
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./www:/var/www/html
links:
- db
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_PASSWORD: wordpress
alpine:
image: petehouston/docker-alpine-php-composer:latest
links:
- wordpress
So my problem is I'm trying to use the composer of the alpine container to manager my Wordpress in the wordpress container but when i try to use the following command:
docker run --rm -v $(pwd):/www -w /wordpress/var/www/html composer/composer create-project roots/sage your-theme-name 8.5.0
nothing happens, and the alpine container doesn't stay up, after i run compose-docker.up he exits
You can't access to Wordpress container from Alpine container using -w /wordpress/var/www/html.
As far as I understand, image petehouston/docker-alpine-php-composer:latest provides PHP deployment environment. That means you should use this image instead of wordpress image.
Your compose file can be like
version: '2'
services:
db:
image: mysql:5.7
volumes:
- ./db:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
alpine:
image: petehouston/docker-alpine-php-composer:latest
volumes:
- ./www:/home
links:
- db
ports:
- "8000:80"
command: composer require phpunit/phpunit
restart: always
Plz give me feedback. I'm sorry because i can't comment to get more information from you. Should you still get errors, comment here. I'll recheck

Resources