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.
Related
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.
I would like to deploy my instance of wordpress using docker compose.
I have docker-compose code:
version: '3.3'
services:
wordpress:
image: wordpress:latest
ports:
- "8000:80"
restart: always
volumes:
- ./data-docker/wordpress:/data
environment:
WORDPRESS_DB_HOST: host.docker.internal:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD:
WORDPRESS_DB_NAME: wordpress
I would like to have some "wordpress" folder contains data (images, etc) on my local machine to be able make a backup of current data. I tried to use ./data-docker/wordpress:/data but this folder is still empty.
Where are for example uploaded images stored? And how can I backup it?
I know that there is also mysql - it is backuped separately.
According to wordpress docker documentation the following should work:
...
volumes:
- ./data-docker/wordpress:/var/www/html
...
There is a question that asks about volumes, mine is a bit different.
What I'm interested in is that when I use a simple docker-compose.yml file
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: user
MYSQL_PASSWORD: password
app:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
volumes:
- .:/var/www/html/
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
volumes:
db_data:
The default image somehow downloads the entire WordPress installation to my host. How does it do that?
I'm asking, because I have a custom Dockerfile in which I ADD the wp zip file, unzip it and put the contents to /var/www/html which is mapped in my docker-compose.yml file in the ../:/var/www/html (my docker-compose.yml file is in the project-root/.docker/ folder so I map the project root to the WP root).
When I tried with the official image the contents were copied to my host, so I'm clearly missing some crucial part that is in the official images. But which one?
So it turns out that you have to copy/download/install using wpcli the WP inside the entrypoint script, and native WP docker images are doing that. Either that or inside the CMD command.
It's the same with this question.
Once done there, all the files in the container will appear in the host as well.
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
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