Skip to content

Commit bcdd405

Browse files
authored
Merge pull request #503 from infosiftr/pre-create-wp-content
Pre-create "wp-content" (and subdirectories) with wide permissions for users who bind-mount directly into them
2 parents 2e0d223 + 403aefd commit bcdd405

25 files changed

+139
-36
lines changed

Dockerfile-alpine.template

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ RUN { \
6868
echo 'html_errors = Off'; \
6969
} > /usr/local/etc/php/conf.d/error-logging.ini
7070
%%VARIANT_EXTRAS%%
71-
VOLUME /var/www/html
7271

7372
ENV WORDPRESS_VERSION %%WORDPRESS_VERSION%%
7473
ENV WORDPRESS_SHA1 %%WORDPRESS_SHA1%%
@@ -79,7 +78,17 @@ RUN set -ex; \
7978
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8079
tar -xzf wordpress.tar.gz -C /usr/src/; \
8180
rm wordpress.tar.gz; \
82-
chown -R www-data:www-data /usr/src/wordpress
81+
chown -R www-data:www-data /usr/src/wordpress; \
82+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
83+
mkdir wp-content; \
84+
for dir in /usr/src/wordpress/wp-content/*/; do \
85+
dir="$(basename "${dir%/}")"; \
86+
mkdir "wp-content/$dir"; \
87+
done; \
88+
chown -R www-data:www-data wp-content; \
89+
chmod -R 777 wp-content
90+
91+
VOLUME /var/www/html
8392

8493
COPY docker-entrypoint.sh /usr/local/bin/
8594

Dockerfile-cli.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ RUN set -ex; \
6060
mkdir -p /var/www/html; \
6161
chown -R www-data:www-data /var/www/html
6262
WORKDIR /var/www/html
63-
VOLUME /var/www/html
6463

6564
# https://make.wordpress.org/cli/2018/05/31/gpg-signature-change/
6665
# pub rsa2048 2018-05-31 [SC]
@@ -93,6 +92,8 @@ RUN set -ex; \
9392
\
9493
wp --allow-root --version
9594

95+
VOLUME /var/www/html
96+
9697
COPY docker-entrypoint.sh /usr/local/bin/
9798

9899
ENTRYPOINT ["docker-entrypoint.sh"]

Dockerfile-debian.template

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ RUN { \
7373
echo 'html_errors = Off'; \
7474
} > /usr/local/etc/php/conf.d/error-logging.ini
7575
%%VARIANT_EXTRAS%%
76-
VOLUME /var/www/html
7776

7877
ENV WORDPRESS_VERSION %%WORDPRESS_VERSION%%
7978
ENV WORDPRESS_SHA1 %%WORDPRESS_SHA1%%
@@ -84,7 +83,17 @@ RUN set -ex; \
8483
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8584
tar -xzf wordpress.tar.gz -C /usr/src/; \
8685
rm wordpress.tar.gz; \
87-
chown -R www-data:www-data /usr/src/wordpress
86+
chown -R www-data:www-data /usr/src/wordpress; \
87+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
88+
mkdir wp-content; \
89+
for dir in /usr/src/wordpress/wp-content/*/; do \
90+
dir="$(basename "${dir%/}")"; \
91+
mkdir "wp-content/$dir"; \
92+
done; \
93+
chown -R www-data:www-data wp-content; \
94+
chmod -R 777 wp-content
95+
96+
VOLUME /var/www/html
8897

8998
COPY docker-entrypoint.sh /usr/local/bin/
9099

docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.2/apache/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ RUN set -eux; \
9191
# (replace all instances of "%h" with "%a" in LogFormat)
9292
find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
9393

94-
VOLUME /var/www/html
9594

9695
ENV WORDPRESS_VERSION 5.4.2
9796
ENV WORDPRESS_SHA1 e5631f812232fbd45d3431783d3db2e0d5670d2d
@@ -102,7 +101,17 @@ RUN set -ex; \
102101
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
103102
tar -xzf wordpress.tar.gz -C /usr/src/; \
104103
rm wordpress.tar.gz; \
105-
chown -R www-data:www-data /usr/src/wordpress
104+
chown -R www-data:www-data /usr/src/wordpress; \
105+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
106+
mkdir wp-content; \
107+
for dir in /usr/src/wordpress/wp-content/*/; do \
108+
dir="$(basename "${dir%/}")"; \
109+
mkdir "wp-content/$dir"; \
110+
done; \
111+
chown -R www-data:www-data wp-content; \
112+
chmod -R 777 wp-content
113+
114+
VOLUME /var/www/html
106115

107116
COPY docker-entrypoint.sh /usr/local/bin/
108117

php7.2/apache/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.2/cli/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ RUN set -ex; \
5959
mkdir -p /var/www/html; \
6060
chown -R www-data:www-data /var/www/html
6161
WORKDIR /var/www/html
62-
VOLUME /var/www/html
6362

6463
# https://make.wordpress.org/cli/2018/05/31/gpg-signature-change/
6564
# pub rsa2048 2018-05-31 [SC]
@@ -92,6 +91,8 @@ RUN set -ex; \
9291
\
9392
wp --allow-root --version
9493

94+
VOLUME /var/www/html
95+
9596
COPY docker-entrypoint.sh /usr/local/bin/
9697

9798
ENTRYPOINT ["docker-entrypoint.sh"]

php7.2/fpm-alpine/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ RUN { \
6767
echo 'html_errors = Off'; \
6868
} > /usr/local/etc/php/conf.d/error-logging.ini
6969

70-
VOLUME /var/www/html
7170

7271
ENV WORDPRESS_VERSION 5.4.2
7372
ENV WORDPRESS_SHA1 e5631f812232fbd45d3431783d3db2e0d5670d2d
@@ -78,7 +77,17 @@ RUN set -ex; \
7877
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
7978
tar -xzf wordpress.tar.gz -C /usr/src/; \
8079
rm wordpress.tar.gz; \
81-
chown -R www-data:www-data /usr/src/wordpress
80+
chown -R www-data:www-data /usr/src/wordpress; \
81+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
82+
mkdir wp-content; \
83+
for dir in /usr/src/wordpress/wp-content/*/; do \
84+
dir="$(basename "${dir%/}")"; \
85+
mkdir "wp-content/$dir"; \
86+
done; \
87+
chown -R www-data:www-data wp-content; \
88+
chmod -R 777 wp-content
89+
90+
VOLUME /var/www/html
8291

8392
COPY docker-entrypoint.sh /usr/local/bin/
8493

php7.2/fpm-alpine/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.2/fpm/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ RUN { \
7272
echo 'html_errors = Off'; \
7373
} > /usr/local/etc/php/conf.d/error-logging.ini
7474

75-
VOLUME /var/www/html
7675

7776
ENV WORDPRESS_VERSION 5.4.2
7877
ENV WORDPRESS_SHA1 e5631f812232fbd45d3431783d3db2e0d5670d2d
@@ -83,7 +82,17 @@ RUN set -ex; \
8382
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8483
tar -xzf wordpress.tar.gz -C /usr/src/; \
8584
rm wordpress.tar.gz; \
86-
chown -R www-data:www-data /usr/src/wordpress
85+
chown -R www-data:www-data /usr/src/wordpress; \
86+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
87+
mkdir wp-content; \
88+
for dir in /usr/src/wordpress/wp-content/*/; do \
89+
dir="$(basename "${dir%/}")"; \
90+
mkdir "wp-content/$dir"; \
91+
done; \
92+
chown -R www-data:www-data wp-content; \
93+
chmod -R 777 wp-content
94+
95+
VOLUME /var/www/html
8796

8897
COPY docker-entrypoint.sh /usr/local/bin/
8998

php7.2/fpm/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.3/apache/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ RUN set -eux; \
9292
# (replace all instances of "%h" with "%a" in LogFormat)
9393
find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
9494

95-
VOLUME /var/www/html
9695

9796
ENV WORDPRESS_VERSION 5.4.2
9897
ENV WORDPRESS_SHA1 e5631f812232fbd45d3431783d3db2e0d5670d2d
@@ -103,7 +102,17 @@ RUN set -ex; \
103102
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
104103
tar -xzf wordpress.tar.gz -C /usr/src/; \
105104
rm wordpress.tar.gz; \
106-
chown -R www-data:www-data /usr/src/wordpress
105+
chown -R www-data:www-data /usr/src/wordpress; \
106+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
107+
mkdir wp-content; \
108+
for dir in /usr/src/wordpress/wp-content/*/; do \
109+
dir="$(basename "${dir%/}")"; \
110+
mkdir "wp-content/$dir"; \
111+
done; \
112+
chown -R www-data:www-data wp-content; \
113+
chmod -R 777 wp-content
114+
115+
VOLUME /var/www/html
107116

108117
COPY docker-entrypoint.sh /usr/local/bin/
109118

php7.3/apache/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.3/cli/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ RUN set -ex; \
6060
mkdir -p /var/www/html; \
6161
chown -R www-data:www-data /var/www/html
6262
WORKDIR /var/www/html
63-
VOLUME /var/www/html
6463

6564
# https://make.wordpress.org/cli/2018/05/31/gpg-signature-change/
6665
# pub rsa2048 2018-05-31 [SC]
@@ -93,6 +92,8 @@ RUN set -ex; \
9392
\
9493
wp --allow-root --version
9594

95+
VOLUME /var/www/html
96+
9697
COPY docker-entrypoint.sh /usr/local/bin/
9798

9899
ENTRYPOINT ["docker-entrypoint.sh"]

php7.3/fpm-alpine/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ RUN { \
6868
echo 'html_errors = Off'; \
6969
} > /usr/local/etc/php/conf.d/error-logging.ini
7070

71-
VOLUME /var/www/html
7271

7372
ENV WORDPRESS_VERSION 5.4.2
7473
ENV WORDPRESS_SHA1 e5631f812232fbd45d3431783d3db2e0d5670d2d
@@ -79,7 +78,17 @@ RUN set -ex; \
7978
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8079
tar -xzf wordpress.tar.gz -C /usr/src/; \
8180
rm wordpress.tar.gz; \
82-
chown -R www-data:www-data /usr/src/wordpress
81+
chown -R www-data:www-data /usr/src/wordpress; \
82+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
83+
mkdir wp-content; \
84+
for dir in /usr/src/wordpress/wp-content/*/; do \
85+
dir="$(basename "${dir%/}")"; \
86+
mkdir "wp-content/$dir"; \
87+
done; \
88+
chown -R www-data:www-data wp-content; \
89+
chmod -R 777 wp-content
90+
91+
VOLUME /var/www/html
8392

8493
COPY docker-entrypoint.sh /usr/local/bin/
8594

php7.3/fpm-alpine/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.3/fpm/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ RUN { \
7373
echo 'html_errors = Off'; \
7474
} > /usr/local/etc/php/conf.d/error-logging.ini
7575

76-
VOLUME /var/www/html
7776

7877
ENV WORDPRESS_VERSION 5.4.2
7978
ENV WORDPRESS_SHA1 e5631f812232fbd45d3431783d3db2e0d5670d2d
@@ -84,7 +83,17 @@ RUN set -ex; \
8483
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
8584
tar -xzf wordpress.tar.gz -C /usr/src/; \
8685
rm wordpress.tar.gz; \
87-
chown -R www-data:www-data /usr/src/wordpress
86+
chown -R www-data:www-data /usr/src/wordpress; \
87+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
88+
mkdir wp-content; \
89+
for dir in /usr/src/wordpress/wp-content/*/; do \
90+
dir="$(basename "${dir%/}")"; \
91+
mkdir "wp-content/$dir"; \
92+
done; \
93+
chown -R www-data:www-data wp-content; \
94+
chmod -R 777 wp-content
95+
96+
VOLUME /var/www/html
8897

8998
COPY docker-entrypoint.sh /usr/local/bin/
9099

php7.3/fpm/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.4/apache/Dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ RUN set -eux; \
9292
# (replace all instances of "%h" with "%a" in LogFormat)
9393
find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
9494

95-
VOLUME /var/www/html
9695

9796
ENV WORDPRESS_VERSION 5.4.2
9897
ENV WORDPRESS_SHA1 e5631f812232fbd45d3431783d3db2e0d5670d2d
@@ -103,7 +102,17 @@ RUN set -ex; \
103102
# upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
104103
tar -xzf wordpress.tar.gz -C /usr/src/; \
105104
rm wordpress.tar.gz; \
106-
chown -R www-data:www-data /usr/src/wordpress
105+
chown -R www-data:www-data /usr/src/wordpress; \
106+
# pre-create wp-content (and single-level children) for folks who want to bind-mount themes, etc so permissions are pre-created properly instead of root:root
107+
mkdir wp-content; \
108+
for dir in /usr/src/wordpress/wp-content/*/; do \
109+
dir="$(basename "${dir%/}")"; \
110+
mkdir "wp-content/$dir"; \
111+
done; \
112+
chown -R www-data:www-data wp-content; \
113+
chmod -R 777 wp-content
114+
115+
VOLUME /var/www/html
107116

108117
COPY docker-entrypoint.sh /usr/local/bin/
109118

php7.4/apache/docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
5252
fi
5353

5454
echo >&2 "WordPress not found in $PWD - copying now..."
55-
if [ -n "$(ls -A)" ]; then
55+
if [ -n "$(find -mindepth 1 -maxdepth 1 -not -name wp-content)" ]; then
5656
echo >&2 "WARNING: $PWD is not empty! (copying anyhow)"
5757
fi
5858
sourceTarArgs=(

php7.4/cli/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ RUN set -ex; \
6060
mkdir -p /var/www/html; \
6161
chown -R www-data:www-data /var/www/html
6262
WORKDIR /var/www/html
63-
VOLUME /var/www/html
6463

6564
# https://make.wordpress.org/cli/2018/05/31/gpg-signature-change/
6665
# pub rsa2048 2018-05-31 [SC]
@@ -93,6 +92,8 @@ RUN set -ex; \
9392
\
9493
wp --allow-root --version
9594

95+
VOLUME /var/www/html
96+
9697
COPY docker-entrypoint.sh /usr/local/bin/
9798

9899
ENTRYPOINT ["docker-entrypoint.sh"]

0 commit comments

Comments
 (0)