-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
124 lines (97 loc) · 3.5 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# https://docs.docker.com/engine/reference/builder/
# https://hub.docker.com/_/debian
FROM debian:bookworm-slim
# Configure apt not to prompt during docker build
ARG DEBIAN_FRONTEND=noninteractive
# Configure apt to avoid installing recommended and suggested packages
RUN apt-config dump \
| grep -E '^APT::Install-(Recommends|Suggests)' \
| sed -e's/1/0/' \
| tee /etc/apt/apt.conf.d/99no-recommends-no-suggests
# Resynchronize the package index files from their sources
RUN apt-get update
# Install packages
RUN apt-get install -y \
apache2 \
apache2-utils \
ca-certificates \
curl \
git \
less \
libapache2-mod-php \
mariadb-client \
php8.2 \
php8.2-mbstring \
php8.2-mysql \
php8.2-pdo \
php8.2-xml \
sudo \
unzip \
vim \
wget \
&& update-ca-certificates
# Clean up packages: Saves space by removing unnecessary package files
# and lists
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/*
# Add Apache2's www-data user to sudo group and enable passwordless startup
RUN adduser www-data sudo
COPY config/www-data_startupservice /etc/sudoers.d/www-data_startupservice
# Add Apache2 service startup script
COPY config/startupservice.sh /startupservice.sh
RUN chmod +x /startupservice.sh
CMD ["sudo", "--preserve-env", "/startupservice.sh"]
# Expose ports for Apache
EXPOSE 80
# Enable Apache modules
RUN a2enmod headers
RUN a2enmod php8.2
RUN a2enmod rewrite
# Configure PHP
COPY config/90-local.ini /etc/php/8.2/apache2/conf.d/
# Install Composer
# https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos
RUN curl -sS https://getcomposer.org/installer \
| php -- --install-dir=/usr/local/bin --filename=composer
# Create compose directory for www-data
RUN mkdir /var/www/.composer
RUN chown -R www-data:www-data /var/www/.composer
# Install WordPress CLI (WP-CLI)
# https://wp-cli.org/#installing
RUN curl -L \
https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar \
-o wp-cli.phar \
&& chmod +x wp-cli.phar \
&& mv wp-cli.phar /usr/local/bin/wp
# Create WP-CLI directory for www-data
RUN mkdir /var/www/.wp-cli
RUN chown -R www-data:www-data /var/www/.wp-cli
# Create the index directory and set permissions
RUN mkdir -p /var/www/index/wp-content/uploads
RUN chown -R www-data:www-data /var/www/index
# Use WP-CLI to intall WordPress
USER www-data
WORKDIR /var/www/index
ARG WP_VERSION
RUN wp core download --version=$WP_VERSION
# Add WordPress basic configuration
# 1) Download wp-config-docker.php for use as wp-config.php. Friendly view at:
# https://github.com/docker-library/wordpress/blob/master/latest/php8.2/apache/wp-config-docker.php
RUN curl -L \
https://raw.githubusercontent.com/docker-library/wordpress/master/latest/php8.2/apache/wp-config-docker.php \
-o /var/www/index/wp-config.php
# 2) Use awk to replace all instances of "put your unique phrase here" with a
# properly unique string (for AUTH_KEY and friends to have safe defaults if
# they aren't specified with environment variables)
# Based on:
# https://github.com/docker-library/wordpress/blob/master/latest/php8.2/apache/docker-entrypoint.sh
RUN awk ' \
/put your unique phrase here/ { \
cmd = "head -c1m /dev/urandom | sha1sum | cut -d\\ -f1"; \
cmd | getline str; \
close(cmd); \
gsub("put your unique phrase here", str); \
} \
{ print } \
' /var/www/index/wp-config.php > /var/www/index/wp-config.tmp \
&& mv /var/www/index/wp-config.tmp /var/www/index/wp-config.php