I’ve been playing around with this mediawiki image:
docker pull mediawiki:1.41.0
Here is my docker-compose.yml
:
version: '3.6'
networks:
my_network:
external: true
services:
mediawiki:
image: mediawiki:1.41.0
container_name: mediawiki
restart: always
networks:
- my_network
volumes:
- './mediawiki/html/:/var/www/html/:rw'
- './mediawiki/data/:/var/www/data/:rw'
Without the volumes
configuration everything works as expected. I’m able to go through the initial mediawiki setup process and generate the LocalSettings.php
file and move it into the container with docker cp LocalSettings.php mediawiki:/var/www/html
. When I run docker compose restart
the SQLite DB is created, all my settings are applied, I can browse to the web interface, make new pages, etc.
With the volumes
configuration in the compose file, the /var/www/html
directory in the container never gets populated if I run docker compose up --force-recreate -d
. If I remove the volumes
configuration and go through the setup process described above then add the volumes
configuration back in and run docker compose up -d
, the contents of the container’s /var/www/html
directory are blow away! This causes the container’s Apache server to issue me a 403 Forbidden error when I try to access the web interface.
I’ve never had permission problems with volumes between host/container, but just to be sure it wasn’t a permission problem I gave the directories on the host 777 permissions and even tried changing the owner and group to www-data
, and confirmed that the www-data
user/group had the same ID between the host/container.
I’m kind of at a loss now. What is causing this?
Update 1
I’ve had a fundamental misunderstanding of how volumes work until I read this. Now I realize that the shorthand volume
blocks in my config above were actually doing a bind
. It was easy for me to believe this because up until now all the volumes I’ve delt with were bound to container directories that did not contain files that were actually part of the image, so I’ve never seen this behavior. Though I do have this working now, I still have not been able to solve my problem the way I want. My updated docker-compose.yml
:
version: '3.6'
networks:
my_network:
external: true
volumes:
html:
data:
services:
mediawiki:
image: mediawiki:1.41.0
container_name: mediawiki
restart: always
networks:
- docker_net
volumes:
- type: volume
source: html
target: /var/www/html
- type: volume
source: data
target: /var/www/data
After running docker compose down -v
and docker compose up --force-recreate -d
the mediawiki instance is working, but the whole point of me trying to configure volumes was to get access to the data in the container for backup purposes. I technically do have access to it, but it is way off in /var/lib/docker/volumes/mediawiki_html/_data
and /var/lib/docker/volumes/mediawiki_data/_data
. I guess I can symlink to those directories, but feels like there should be a cleaner way to get at container data and have it next to its docker-compose.yml
file.