This is my docker-composer.yml for wordpress:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./all:/var/www/html
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- "8084:80"
links:
- db:db
volumes:
db_data: {}
The folder all contains all the files that ship from the wordpress docker image. However, they all have user/group www-data:www-data and the permission of the files is 644 and from folders 755, i.e. even if I add myself to the www-data group I have no right to modfiy or create files.
My research:
I found at write in shared volumes docker that someone had the opposite problem, he created files and his docker image could not access it. The solution seems to be to run docker and create a file with user www-data - but I don't see how I can apply this to my problem.
I tried to add user: "1000:1000 in the worpdress service inside docker-composer.yml, in hope, that all file permissions set by docker would be from my user. However, I get 1000 lines of erros of this form:
wordpress_1 | tar: ./wp-admin: Cannot mkdir: Permission denied
wordpress_1 | tar: ./wp-admin/options-reading.php: Cannot open: No such file or directory
I ended up just to change the file permission of all files and folders from folder all to 777 recursively. Since this is only local development, there is no risk involved.
When I create a new file from my host it only has 644 permission, i.e. it can be read by from localhost but not edited, for that I would manually need to change the permission to 777.
A bit old of a thread but i also was looking on how to update files on a wordpress:latest container.
I ended using a docker cp on the file i need to change. For instance :
docker cp ./functions_edited.php 6666aa5bbd76:/var/www/html/wp-content/themes/twentytwentytwo/functions.php
to edit the theme functions on the running container.
This works for me since i don't need to persists my changes when the container dies and i need just to change a single file. Maybe this is not your use case.
Related
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 getting permission issues (or so it appears) on a bind mounted volume on a Mac that is preventing themes and plugins from being installed. I'm using docker-compose to create my container as follows.
wordpress:
depends_on:
- db
image: wordpress
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: *****
WORDPRESS_DB_NAME: wordpress
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
The Container is created no problem. On my host mac the wp-content directory is created just fine and correctly populated. I can connect to my container (using docker exec) and see the mounted volume has default permissions of drwxr-xr-x 1 1000 staff 160 Aug 14 23:04 wp-content Whenever I try to install a theme or plugin it prompts for FTP credentials or if I add define('FS_METHOD', 'direct') to wp-config.php fails with "Could not create directory". I've also tried making permissions to wp-config from my host host wide open with chmod -R 777 wp-content and changing ownership from the container with chown -r www-data:www-data wp-content. Enabling debugging produces no debug.log in wp-content. I've also tried running apache as user 1000 using user: "1000:1000" and/or environment: APACHE_RUN_USER/APACHE_RUN_GROUP as per https://github.com/docker-library/wordpress/pull/249. Nothing seems to make any difference and I have no idea what to try next. I suspect this is something really simple but have exhausted everything I can find. Any tips or help would be greatly appreciated. I'm just trying to do some basic plugin development and would like to edit wp-content locally.
I think you need to make volume from the root directory of your wordpress install.
There is my docker-compose.yml file
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: dbname
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbpassword
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wp_data:/var/www/html
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: dbuser
WORDPRESS_DB_PASSWORD: dbpassword
WORDPRESS_DB_NAME: dbname
volumes:
db_data: {}
wp_data:
driver: local
driver_opts:
type: none
o: bind
device: /var/www/html/
Copy plugins to wordpress base image. Plugins folders are visible in cmd CMD using command docker run -it --rm arslanliaqat/testwordpressimage sh but not visible in volume mounted Folder. I have attached the screenshot of cmd commands and folder as well.
Dockerfile
FROM wordpress:php7.1-apache
WORKDIR /var/www/html
COPY plugins/wordpress-seo/ /var/www/html/wp-content/plugins/wordpress-seo/
COPY plugins/wp-super-cache/ /var/www/html/wp-content/plugins/wp-super-cache/
EXPOSE 80
Docker-compose.yml
version: '3.3'
services:
db:
image: 'mysql:5.7'
volumes:
- './dbdata:/var/lib/mysql'
restart: always
environment:
#PMA_HOST: db
#PMA_PORT: 3000
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: 'arslanliaqat/testwordpressimage:latest'
#image: 'wordpress:latest'
volumes:
#- './wordpress/:/var/www/html/'
- './Wordpress:/var/www/html'
#- './wordpress:/var/www/html'
#- './wordpress/wp-content/plugins/wordpress-seo/:/wp-content/wordpress-seo/'
#- './wordpress/wp-content/plugins/wp-super-cache/:/wp-content/wp-super-cache/'
# - './plugins/wordpress-seo/:/var/www/html/wp-content/plugins/wordpress-seo/'
# - './plugins/wp-super-cache/:/var/www/html/wp-content/plugins/wp-super-cache/'
- './docker/wordpress/php/php.ini:/usr/local/etc/php/conf.d/php.ini:ro'
ports:
- '8000:80'
restart: always
environment:
WP_LOCALE: en_US
WORDPRESS_LOCALE: en_US
WORDPRESS_DB_HOST: 'db:3306'
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_TABLE_PREFIX: wp_
WORDPRESS_DEBUG: 1
WORDPRESS_DB_NAME: wordpress
working_dir: /var/www/html
volumes:
db_data:
wordpress:
Bind mounts have been around since the early days of Docker. Bind mounts have limited functionality compared to volumes. When you use a bind mount, a file or directory on the host machine is mounted into a container.
That means: when you define - './Wordpress:/var/www/html' in compose, the directory /var/www/html in container will be override by the directory ./Wordpress on host. So you can just see the contents of your hosts.
But for this, you did not use bind mount volume, so your things in container not override by host directory.
Detail refers to official guide
I have all set in my local machine for virtual machine shared folders. I have following code in my Docker compose file for Wordpress service. but not sure how the volumes work here. Can you please explain?
version: '2'
services:
database:
image: mysql:5.6
volumes:
- ./mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
restart: unless-stopped
wordpress:
image: wordpress:4.9.6
ports:
- 49160:80
links:
- database:mysql
volumes:
- ./wordpress:/var/www/html/wp-content
environment:
WORDPRESS_DB_PASSWORD: password
restart: unless-stopped
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- database:db
ports:
- 8080:80
Does the above volumes line of code mean, does it need to create a WordPress folder in my docker-compsose.yml file that I am currently running?
Or is it anyhow related to my shared folders in virtual machine?
Basically volumes are instruments for Docker so it can retain data. Docker containers are generally designed to be stateless, but if you need to retain state/information between runs, that's where volumes come in.
You can create an unnamed volume in the following way:
volumes:
- /var/www/html/wp-content
This will retain your wp-content folder in the internal volumes storage without a particular name.
A second way would be to give it a name, making it a named volume:
volumes:
- mywp:/var/www/html/wp-content
And the final type, which is also what you are doing, is called a Volume Bind. This basically binds/mounts the content of a folder on your host machine in the container. So if you change a file in either place, it will be saved on the other.
volumes:
- ./wordpress:/var/www/html/wp-content
In order to use your Volume Bind, you will need to create the folder "wordpress" in the folder where you're running the docker-compose.yaml (usually your root folder). Afterwards, when your installation changes within the container, it will also change on the bind and vice-versa.
EDIT: In your particular case the following should work:
version: '3.2'
services:
database:
image: mysql:5.6
volumes:
- ./mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
restart: unless-stopped
wordpress:
image: wordpress:4.9.6
ports:
- 49160:80
links:
- database:mysql
volumes:
- type: bind
source: ./wordpress
target: /var/www/html/wp-content
environment:
WORDPRESS_DB_PASSWORD: password
restart: unless-stopped
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- database:db
ports:
- 8080:80
Adding a volume to your docker-compose.yml file will enable you to 'mount' content from your local file system into the running container.
So, about the following line here:
volumes:
- ./wordpress:/var/www/html/wp-content
This means that whatever's in your local wordpress directory will be placed in the /var/www/html/wp-content directory inside your container. This is useful because it allows you to develop themes and plugins locally and automatically inject them into the running container.
To avoid confusion, I'd recommend renaming wordpress to something else, so it's clear that you're mounting only your WordPress content, and not core files themselves.
I have a similar setup here, in case you need another reference:
https://github.com/alexmacarthur/wp-skateboard