@@ -3,8 +3,14 @@ ARG PHP_VERSION=7.4.33
33
44FROM php:$PHP_VERSION-fpm-$DEBIAN_VERSION
55
6- ENV SSL_ENABLED="false" ;
7- RUN mkdir "/var/ssl" ;
6+ # Add environment variables for domain and port
7+ ENV SERVER_NAME="example.com"
8+ ENV SSL_ENABLED="false"
9+
10+ ENV WP_DB_HOST="db"
11+ ENV WP_DB_USER="root"
12+ ENV WP_DB_PASSWORD="password"
13+ ENV WP_DB_NAME="wordpress"
814
915# Add Debian Bookworm repositories and install necessary tools
1016# persistent dependencies
@@ -107,6 +113,14 @@ RUN set -ex; \
107113 ; \
108114 rm -rf /var/lib/apt/lists/*
109115
116+ # Install Certbot using the package manager
117+ RUN set -eux; \
118+ apt-get update; \
119+ apt-get install -y --no-install-recommends certbot python3-certbot-nginx cron
120+
121+ # Add a cron job for Certbot auto-renewal
122+ RUN echo "0 0,12 * * * certbot renew --quiet" | crontab -
123+
110124# Update Nginx to run as www-data
111125RUN sed -i 's/user nginx;/user www-data;/' /etc/nginx/nginx.conf
112126RUN usermod -a -G nginx www-data
@@ -115,15 +129,20 @@ RUN usermod -a -G nginx www-data
115129RUN mkdir /usr/src/nginx-defaults
116130COPY ./nginx/default.conf /usr/src/nginx-defaults/default.conf
117131COPY ./nginx/wordpress.conf.include /usr/src/nginx-defaults/wordpress.conf.include
118- COPY ./nginx/default_ssl.conf /usr/src/nginx-defaults/default_ssl.conf
119- COPY ./nginx/options-ssl-nginx.conf /usr/src/nginx-defaults/options-ssl-nginx.conf
132+ # COPY ./nginx/default_ssl.conf /usr/src/nginx-defaults/default_ssl.conf
133+ # COPY ./nginx/options-ssl-nginx.conf /usr/src/nginx-defaults/options-ssl-nginx.conf
134+ # RUN mkdir "/var/ssl";
120135
121136# Expose the default Nginx port
122137EXPOSE 80
123- EXPOSE 443
138+ # Expose the default Nginx SSL port if SSL is enabled
139+ RUN if [ "$SSL_ENABLED" = "true" ]; then \
140+ echo "EXPOSE 443" ; \
141+ fi
124142
125143COPY ./entrypoint.sh /entrypoint.sh
126144RUN chmod +x /entrypoint.sh
145+
127146ENTRYPOINT ["/entrypoint.sh" ]
128147
129148
0 commit comments