Skip to content

Commit 240082f

Browse files
committed
remap docker ephemeral ports to 80 for WP Site Health requesting external ports.
1 parent 5610a1d commit 240082f

File tree

3 files changed

+45
-20
lines changed

3 files changed

+45
-20
lines changed

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,21 @@ RUN chmod +x /etc/update-motd.d/*
174174
RUN echo \
175175
&& echo LS_OPTIONS='--color=auto' >> /root/.bashrc \
176176
&& echo run-parts /etc/update-motd.d/ >> /root/.bashrc \
177+
&& echo alias wp='wp --allow-root' \
177178
&& echo cd /usr/src >> /root/.bashrc
178179

180+
# Install IPTables to workaround WordPress internal requests to external ports
181+
# This will be used to remap Docker's entire ephemeral port range back to 80
182+
RUN apt-get update -yqq \
183+
&& apt-get install -y --no-install-recommends \
184+
iptables \
185+
&& apt-get autoremove -yqq \
186+
&& rm -rf /var/lib/apt/lists/*
187+
179188
# Network Debugging Tools
180189
# TODO: Remove or disable if not needed
181190
RUN apt-get update -yqq \
182-
&& apt-get install -y --no-install-recommends \
191+
&& apt-get install -y --no-install-recommends \
183192
iputils-ping \
184193
dnsutils \
185194
vim \

bin/docker-entrypoint-iop.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ if [[ "$1" != apache2* ]] && [ "$1" != php-fpm ]; then
3333
exit 0
3434
fi
3535

36+
# Check if NET_ADMIN capability is present
37+
if ! iptables -t nat -L >/dev/null 2>&1; then
38+
echo -e "${GOLD}WARNING: IPTables failed due to missing NET_ADMIN capability."
39+
echo -e " Run with --cap-add=NET_ADMIN or add 'cap_add: [NET_ADMIN]' to docker-compose.yml.${RESET}"
40+
fi
41+
# Remap Docker's entire ephemeral port range back to port 80
42+
iptables -t nat -A OUTPUT -p tcp -d "localhost" --dport 49153:65535 -j REDIRECT --to-port 80
43+
3644
# Create a simple phpinfo() page at /info.php
3745
echo '<?php phpinfo();' >/var/www/html/info.php
3846
echo '<?php xdebug_info();' >/var/www/html/xdebug.php
39-
chown $OWNER_GROUP /var/www/html/info.php /var/www/html/xdebug.php
47+
chown www-data:www-data /var/www/html/info.php /var/www/html/xdebug.php
4048

4149
# Finally, we run the original endpoint, as intended, to kickoff the server
4250
exec /usr/local/bin/docker-entrypoint.sh "$@"

boilerplate-tooling/docker-compose.yml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,33 @@ services:
6262
# Apache will throw errors for any ulimit value below 8192
6363
# NOTE THAT THIS MIGHT BE MORE THAN THE SYSTEM OFFERS
6464
# TODO: Still true?
65-
ulimits:
66-
nofile: 8192
65+
# TODO: Testing removal. 2025-03-18
66+
# ulimits:
67+
# nofile: 8192
6768

68-
# Ideas On Purpose's development toolchain
69-
# Image from: https://hub.docker.com/r/ideasonpurpose/docker-build
70-
tools:
71-
# image: ideasonpurpose/docker-build:dev
72-
image: ideasonpurpose/docker-build:0.17.2
73-
user: "${UID:-1000}:${GID:-1000}"
74-
depends_on:
75-
- wordpress
76-
volumes:
77-
- .:/usr/src/site/
78-
ports:
79-
- "${npm_config_port:-8080}:8080"
80-
environment:
81-
PORT: ${npm_config_port:-8080}
82-
entrypoint: npm run
83-
command: start
69+
# Required for iptables port-mapping to work inside the Docker image
70+
# This is used to fix a PHP/WordPress issue where internal requests
71+
# from Site Health tried to load from external ports.
72+
cap_add:
73+
- NET_ADMIN
74+
75+
# # TODO: Deprecated and likely ready to remove 2025-03-18
76+
# # Ideas On Purpose's development toolchain
77+
# # Image from: https://hub.docker.com/r/ideasonpurpose/docker-build
78+
# tools:
79+
# # image: ideasonpurpose/docker-build:dev
80+
# image: ideasonpurpose/docker-build:0.17.2
81+
# user: "${UID:-1000}:${GID:-1000}"
82+
# depends_on:
83+
# - wordpress
84+
# volumes:
85+
# - .:/usr/src/site/
86+
# ports:
87+
# - "${npm_config_port:-8080}:8080"
88+
# environment:
89+
# PORT: ${npm_config_port:-8080}
90+
# entrypoint: npm run
91+
# command: start
8492

8593
# Utility service for running composer commands
8694
# Image from: https://hub.docker.com/_/composer

0 commit comments

Comments
 (0)