I'm trying to create a docker container, using docker-compose, which mounts a volume on the local filesystem (for the container's /var/www/html) then adds a directory called maps and chowns and chmods is to www-data, so that the web server can write files into it.
I've tried a couple of approaches, using an entrypoint.sh script like this:
Dockerfile
FROM php:5.6-apache
COPY apache-config.conf /etc/apache2/sites-enabled/000-default.conf
RUN a2enmod rewrite headers
RUN service apache2 restart
COPY entrypoint.sh /entrypoint.sh
RUN chmod 0755 /entrypoint.sh
docker-compose.yml (stuff in {} just comes from a .env file)
version: '2'
services:
webserver:
build: ./docker/webserver
image: web
ports:
- "8080:80"
volumes:
- ./web:${APACHE_DOC_ROOT}
links:
- db
environment:
- HTTP_ROOT=http://${DOCKER_HOST_IP}:${DOCKER_HOST_PORT}/
- PHP_TMP_DIR=${PHP_TMP_DIR}
- APACHE_LOG_DIR=${APACHE_LOG_DIR}
- APACHE_DOC_ROOT=${APACHE_DOC_ROOT}/
- SERVER_ADMIN_EMAIL=${SERVER_ADMIN_EMAIL}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
- MYSQL_DATABASE=${MYSQL_DATABASE}
entrypoint.sh
#!/bin/sh
mkdir /var/www/html/maps
chown www-data /var/www/html/maps
chgrp www-data /var/www/html/maps
exec "$@"
I've also tried without any of the entrypoint.sh stuff, just adding this into the composer.yml (after the environment key):
command: bash -c "mkdir /var/www/html/maps && chown www-data /var/www/html/maps && chgrp www-data /var/www/html/maps"
But both these approaches seem to give no error in docker-compose logs other than
webserver_1 exited with code 0
Not sure if you still have this problem, but maybe adding this will help you. I mean, it resolved my problem - PHP scripts running on the container didn't have write permissions.
RUN usermod -u 1000 www-data
Hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With