How to fix file permissions on wp-content with official wordpress image for docker-compose

Solution:1

You can modify your ./entrypoint.sh script to run the default entrypoint script of the original image after it executes your chown command:

#!/bin/bash
echo Fixing permissions…
chown -R www-data:www-data /var/www/html/wp-content/
docker-entrypoint.sh apache2-foreground

Solution:2

From Docker’s documentation the command you should be using is RUN.

Don’t confuse RUN with CMD. RUN actually runs a command and commits the result; CMD does not execute anything at build time, but specifies the intended command for the image.

So the line in your Dockerfile should be: RUN chown -R www-data:www-data /var/www/html/wp-content

Also, to decrease the number of layers created and the size of your image, I’d chain as many of the RUN commands as possible. For example (not tested):

FROM wordpress:5.1.1

# install dos2unix (fix problem between CRLF and LF) and increase upload limit
RUN apt-get update -y && \
    apt-get install -y dos2unix && \
    touch /usr/local/etc/php/conf.d/uploads.ini \
    && echo "upload_max_filesize = 10M;" >> /usr/local/etc/php/conf.d/uploads.ini && \
    chown -R www-data:www-data /var/www/html/wp-content

# fix permissions issues
COPY entrypoint.sh /
RUN dos2unix /entrypoint.sh && \
    chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]