From 88091d20382db7aac2f8e26a6048f9877fbfed51 Mon Sep 17 00:00:00 2001 From: AH-dark Date: Tue, 10 Sep 2024 14:54:02 +0800 Subject: [PATCH] feat: all in one container --- README.md | 4 ++- all-in-one/Dockerfile | 33 +++++++++++++++++++++ all-in-one/default.conf | 46 ++++++++++++++++++++++++++++++ all-in-one/install-nginx.sh | 30 +++++++++++++++++++ all-in-one/supervisor/nginx.conf | 7 +++++ all-in-one/supervisor/php-fpm.conf | 6 ++++ 6 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 all-in-one/Dockerfile create mode 100644 all-in-one/default.conf create mode 100644 all-in-one/install-nginx.sh create mode 100644 all-in-one/supervisor/nginx.conf create mode 100644 all-in-one/supervisor/php-fpm.conf diff --git a/README.md b/README.md index 5df3dbb..df1e7cf 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# wordpress-container \ No newline at end of file +# wordpress container + +A simple container for running a wordpress site. diff --git a/all-in-one/Dockerfile b/all-in-one/Dockerfile new file mode 100644 index 0000000..1496e23 --- /dev/null +++ b/all-in-one/Dockerfile @@ -0,0 +1,33 @@ +FROM php:8.0-fpm + +# Install dependencies +RUN apt update && apt upgrade -y + +# Install supervisor +RUN apt install -y supervisor + +# Install PHP extensions +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +ARG PHP_EXTENSIONS="gd opcache zip pdo_mysql redis xdebug imagick exif mbstring" +RUN install-php-extensions ${PHP_EXTENSIONS} + +COPY supervisor/php-fpm.conf /etc/supervisor/conf.d/php-fpm.conf + +# Install nginx +COPY install-nginx.sh /tmp/install-nginx.sh +RUN chmod +x /tmp/install-nginx.sh +RUN /tmp/install-nginx.sh +RUN rm -f /tmp/install-nginx.sh + +COPY default.conf /etc/nginx/conf.d/default.conf +COPY supervisor/nginx.conf /etc/supervisor/conf.d/nginx.conf + +# Download WordPress +ARG WORDPRESS_VERSION=latest +RUN curl -o /tmp/wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" +RUN tar -xzf /tmp/wordpress.tar.gz -C /var/www/html --strip-components=1 +RUN rm -f /tmp/wordpress.tar.gz +RUN chmod -R 755 /var/www/html +RUN chown -R www-data:www-data /var/www/html + +ENTRYPOINT ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"] diff --git a/all-in-one/default.conf b/all-in-one/default.conf new file mode 100644 index 0000000..1623fb4 --- /dev/null +++ b/all-in-one/default.conf @@ -0,0 +1,46 @@ +upstream php { + server unix:/var/run/php/php8.0-fpm.sock; +} + +server { + listen 80; + server_name localhost; + root /var/www/html; + + index index.php index.html index.htm; + + # Access log + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location = /robots.txt { + allow all; + log_not_found off; + access_log off; + } + + location / { + # This is cool because no php is touched for static content. + # include the "?$args" part so non-default permalinks doesn't break when using query string + try_files $uri $uri/ /index.php?$args; + } + + # PHP-FPM configuration + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_pass php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } + + # Deny access to .htaccess files, if Apache's document root + # concurs with nginx's one + location ~ /\.ht { + deny all; + } +} diff --git a/all-in-one/install-nginx.sh b/all-in-one/install-nginx.sh new file mode 100644 index 0000000..8c5a98f --- /dev/null +++ b/all-in-one/install-nginx.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +# Install the prerequisites (if not already included in the base image) +apt update && apt install -y curl gnupg2 ca-certificates lsb-release debian-archive-keyring + +# Import an official nginx signing key so apt could verify the packages authenticity. +curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ + > /usr/share/keyrings/nginx-archive-keyring.gpg + +# Verify that the downloaded file contains the proper key +gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg +# The output should contain the full fingerprint 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 + +# Set up the apt repository for stable nginx packages +echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ +http://nginx.org/packages/debian `lsb_release -cs` nginx" \ + > /etc/apt/sources.list.d/nginx.list + +# Set up repository pinning to prefer our packages over distribution-provided ones +echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \ + > /etc/apt/preferences.d/99nginx + +# Update the package lists +apt update + +# Install nginx +apt install -y nginx + +# Clean up to reduce the image size +apt clean && rm -rf /var/lib/apt/lists/* diff --git a/all-in-one/supervisor/nginx.conf b/all-in-one/supervisor/nginx.conf new file mode 100644 index 0000000..684aadf --- /dev/null +++ b/all-in-one/supervisor/nginx.conf @@ -0,0 +1,7 @@ +[program:nginx] +command=/usr/sbin/nginx -g "daemon off;" +autostart=true +autjson=true +autorestart=true +stderr_logfile=/var/log/nginx.err.log +stdout_logfile=/var/log/nginx.out.log diff --git a/all-in-one/supervisor/php-fpm.conf b/all-in-one/supervisor/php-fpm.conf new file mode 100644 index 0000000..0f2058d --- /dev/null +++ b/all-in-one/supervisor/php-fpm.conf @@ -0,0 +1,6 @@ +[program:php] +command=php-fpm -F +autostart=true +autorestart=true +stderr_logfile=/var/log/php.err.log +stdout_logfile=/var/log/php.out.log