Skip to content

Commit c49c79b

Browse files
committed
Migrate to user-based Apache run
1 parent c11af59 commit c49c79b

7 files changed

+75
-58
lines changed

Dockerfile

+23-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
FROM alpine:3.16
1+
FROM alpine:3.20
22

33
RUN apk add --no-cache apache2
4-
RUN mkdir -p /run/apache2 && \
5-
mkdir /var/www/localhost/htdocs/res && \
6-
mkdir /theme1 && \
7-
mkdir /theme2
4+
RUN mkdir -p /run/apache2
85
COPY httpd.conf /etc/apache2/httpd.conf
9-
COPY publish/html5/theme1/* /theme1/
10-
COPY publish/html5/theme2/* /theme2/
11-
COPY publish/html5/game.min.js /var/www/localhost/htdocs/
12-
COPY publish/html5/index.html /var/www/localhost/htdocs/
13-
COPY publish/html5/project.json /var/www/localhost/htdocs/
14-
COPY start.sh /
15-
ENV THEME 1
166

17-
EXPOSE 80
7+
RUN addgroup -S container && \
8+
adduser -S container -G container
9+
RUN chown -R container.container /run
10+
USER container:container
1811

19-
CMD ["/start.sh"]
12+
RUN mkdir -p /home/container/www/htdocs/res && \
13+
mkdir -p /home/container/www/logs && \
14+
mkdir -p /home/container/run/apache2 && \
15+
mkdir /home/container/theme1 && \
16+
mkdir /home/container/theme2
17+
18+
COPY publish/html5/theme1/* /home/container/theme1/
19+
COPY publish/html5/theme2/* /home/container/theme2/
20+
COPY publish/html5/game.min.js /home/container/www/htdocs/
21+
COPY publish/html5/index.html /home/container/www/htdocs/
22+
COPY publish/html5/project.json /home/container/www/htdocs/
23+
COPY start.sh /home/container
24+
ENV THEME=1
25+
26+
EXPOSE 8080
27+
28+
CMD ["/home/container/start.sh"]

Dockerfile.fedora

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
FROM fedora:36
1+
FROM fedora:39
2+
3+
RUN dnf install -y httpd && \
4+
mv /etc/httpd/modules/mod_heartmonitor.so /etc/httpd/modules/mod_heartmonitor.so.bak
25

3-
RUN dnf install -y httpd
4-
RUN mkdir /var/www/html/res && \
5-
mkdir /theme1 && \
6-
mkdir /theme2
76
COPY httpd-fedora.conf /etc/httpd/conf/httpd.conf
8-
COPY publish/html5/theme1/* /theme1/
9-
COPY publish/html5/theme2/* /theme2/
10-
COPY publish/html5/game.min.js /var/www/html/
11-
COPY publish/html5/index.html /var/www/html/
12-
COPY publish/html5/project.json /var/www/html/
13-
COPY start-fedora.sh /start.sh
14-
ENV THEME 1
157

16-
EXPOSE 80
8+
RUN groupadd container && \
9+
useradd -g container container
10+
RUN chown -R container.container /run/httpd
11+
USER container:container
12+
13+
RUN mkdir -p /home/container/www/htdocs/res && \
14+
mkdir -p /home/container/www/logs && \
15+
mkdir -p /home/container/run/apache2 && \
16+
mkdir /home/container/theme1 && \
17+
mkdir /home/container/theme2
18+
19+
COPY publish/html5/theme1/* /home/container/theme1/
20+
COPY publish/html5/theme2/* /home/container/theme2/
21+
COPY publish/html5/game.min.js /home/container/www/htdocs/
22+
COPY publish/html5/index.html /home/container/www/htdocs/
23+
COPY publish/html5/project.json /home/container/www/htdocs/
24+
COPY start.sh /home/container
25+
ENV THEME=1
26+
27+
EXPOSE 8080
1728

18-
CMD ["/start.sh"]
29+
CMD ["/home/container/start.sh"]

docker-compose.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '2'
21
services:
32
dockergame:
43
build:
@@ -7,4 +6,4 @@ services:
76
environment:
87
THEME: "1"
98
ports:
10-
- "8090:80"
9+
- "8090:8080"

httpd-fedora.conf

+9-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
ServerName "localhost.localdomain"
22
ServerRoot "/etc/httpd"
3-
Listen 80
3+
PidFile "/home/container/www/apache.pid"
4+
Mutex flock:/home/container/run/apache2
5+
Listen 8080
46
Include conf.modules.d/*.conf
57
User apache
68
Group apache
@@ -12,14 +14,9 @@ ErrorDocument 404 /404.html
1214
Require all denied
1315
</Directory>
1416

15-
DocumentRoot "/var/www/html"
17+
DocumentRoot "/home/container/www/htdocs"
1618

17-
<Directory "/var/www">
18-
AllowOverride None
19-
Require all granted
20-
</Directory>
21-
22-
<Directory "/var/www/html">
19+
<Directory "/home/container/www/htdocs">
2320
Options Indexes FollowSymLinks
2421
AllowOverride None
2522
Require all granted
@@ -33,7 +30,7 @@ DocumentRoot "/var/www/html"
3330
Require all denied
3431
</Files>
3532

36-
ErrorLog "logs/error_log"
33+
ErrorLog "/home/container/www/logs/error_log"
3734
LogLevel warn
3835

3936
<IfModule log_config_module>
@@ -44,14 +41,14 @@ LogLevel warn
4441
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
4542
</IfModule>
4643

47-
CustomLog "logs/access_log" combined
44+
CustomLog "/home/container/www/logs/access_log" combined
4845
</IfModule>
4946

5047
<IfModule alias_module>
51-
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
48+
ScriptAlias /cgi-bin/ "/home/container/www/cgi-bin/"
5249
</IfModule>
5350

54-
<Directory "/var/www/cgi-bin">
51+
<Directory "/home/container/www/cgi-bin">
5552
AllowOverride None
5653
Options None
5754
Require all granted

httpd.conf

+13-12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ ServerTokens OS
3939
# least PidFile.
4040
#
4141
ServerRoot /var/www
42+
PidFile /home/container/www/apache.pid
4243

4344
#
4445
# Mutex: Allows you to set the mutex mechanism and mutex file directory
@@ -48,7 +49,7 @@ ServerRoot /var/www
4849
# mutex file directory is not on a local disk or is not appropriate for some
4950
# other reason.
5051
#
51-
# Mutex default:/run/apache2
52+
Mutex flock:/home/container/run/apache2
5253

5354
#
5455
# Listen: Allows you to bind Apache to specific IP addresses and/or
@@ -59,7 +60,7 @@ ServerRoot /var/www
5960
# prevent Apache from glomming onto all bound IP addresses.
6061
#
6162
#Listen 12.34.56.78:80
62-
Listen 80
63+
Listen 8080
6364

6465
#
6566
# Dynamic Shared Object (DSO) Support
@@ -175,8 +176,8 @@ LoadModule negotiation_module modules/mod_negotiation.so
175176
# It is usually good practice to create a dedicated user and group for
176177
# running httpd, as with most system services.
177178
#
178-
User apache
179-
Group apache
179+
User container
180+
Group container
180181

181182
</IfModule>
182183

@@ -216,7 +217,7 @@ ServerSignature On
216217
#
217218
# If your host doesn't have a registered DNS name, enter its IP address here.
218219
#
219-
ServerName 127.0.0.1:80
220+
ServerName 127.0.0.1:8080
220221

221222
#
222223
# Deny access to the entirety of your server's filesystem. You must
@@ -240,8 +241,8 @@ ServerName 127.0.0.1:80
240241
# documents. By default, all requests are taken from this directory, but
241242
# symbolic links and aliases may be used to point to other locations.
242243
#
243-
DocumentRoot "/var/www/localhost/htdocs"
244-
<Directory "/var/www/localhost/htdocs">
244+
DocumentRoot "/home/container/www/htdocs"
245+
<Directory "/home/container/www/htdocs">
245246
#
246247
# Possible values for the Options directive are "None", "All",
247248
# or any combination of:
@@ -292,7 +293,7 @@ DocumentRoot "/var/www/localhost/htdocs"
292293
# logged here. If you *do* define an error logfile for a <VirtualHost>
293294
# container, that host's errors will be logged there and not here.
294295
#
295-
ErrorLog logs/error.log
296+
ErrorLog /home/container/www/logs/error.log
296297

297298
#
298299
# LogLevel: Control the number of messages logged to the error_log.
@@ -327,7 +328,7 @@ LogLevel warn
327328
# If you prefer a logfile with access, agent, and referer information
328329
# (Combined Logfile Format) you can use the following directive.
329330
#
330-
CustomLog logs/access.log combined
331+
CustomLog /home/container/www/logs/access.log combined
331332
</IfModule>
332333

333334
<IfModule alias_module>
@@ -357,7 +358,7 @@ LogLevel warn
357358
# client. The same rules about trailing "/" apply to ScriptAlias
358359
# directives as to Alias.
359360
#
360-
ScriptAlias /cgi-bin/ "/var/www/localhost/cgi-bin/"
361+
ScriptAlias /cgi-bin/ "/home/container/www/cgi-bin/"
361362

362363
</IfModule>
363364

@@ -370,10 +371,10 @@ LogLevel warn
370371
</IfModule>
371372

372373
#
373-
# "/var/www/localhost/cgi-bin" should be changed to whatever your ScriptAliased
374+
# "/home/container/www/cgi-bin" should be changed to whatever your ScriptAliased
374375
# CGI directory exists, if you have that configured.
375376
#
376-
<Directory "/var/www/localhost/cgi-bin">
377+
<Directory "/home/container/www/cgi-bin">
377378
AllowOverride None
378379
Options None
379380
Require all granted

start-fedora.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/sh
22

33
if [ "${THEME}" -eq "2" ]; then
4-
cp -a /theme2/* /var/www/html/res/
4+
cp /home/container/theme2/* /home/container/www/htdocs/res/
55
else
6-
cp -a /theme1/* /var/www/html/res/
6+
cp /home/container/theme1/* /home/container/www/htdocs/res/
77
fi
88

99
exec /usr/sbin/httpd -D FOREGROUND

start.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/sh
22

33
if [ "${THEME}" -eq "2" ]; then
4-
cp -a /theme2/* /var/www/localhost/htdocs/res/
4+
cp /home/container/theme2/* /home/container/www/htdocs/res/
55
else
6-
cp -a /theme1/* /var/www/localhost/htdocs/res/
6+
cp /home/container/theme1/* /home/container/www/htdocs/res/
77
fi
88

99
exec /usr/sbin/httpd -D FOREGROUND

0 commit comments

Comments
 (0)