Skip to content

Commit 77ac4a4

Browse files
fix(docker): non-root user
1 parent a8e3af5 commit 77ac4a4

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ ADD nginx.manifest.stale.conf /opt/openresty/nginx/conf/nginx.manifest.stale.con
1111
ADD proxy_auth.lua /opt/openresty/nginx/conf/proxy_auth.lua
1212

1313
RUN apk add --no-cache --update bash openssl \
14-
&& mkdir -p /docker_mirror_cache /certs \
15-
&& chmod +x /generate-certificate.sh /entrypoint.sh
14+
&& mkdir -p /docker_mirror_cache /certs /opt/openresty/nginx/tmp \
15+
&& bash -c 'mkdir -p /opt/openresty/nginx/tmp/{client_body,proxy,fastcgi,scgi,uwsgi}' \
16+
&& chmod +x /generate-certificate.sh /entrypoint.sh \
17+
&& chmod -R g+rwX /opt/openresty/nginx/conf \
18+
&& chmod g+rwX /certs \
19+
&& chmod -R g+rwX /opt/openresty/nginx/tmp
1620

1721
VOLUME /docker_mirror_cache
1822
VOLUME /certs
@@ -75,5 +79,7 @@ ENV PROXY_CONNECT_SEND_TIMEOUT="60s"
7579
# Allow disabling IPV6 resolution, default to false
7680
ENV DISABLE_IPV6="false"
7781

82+
USER 1001
83+
7884
# Did you want a shell? Sorry, the entrypoint never returns, because it runs nginx itself. Use 'docker exec' if you need to mess around internally.
7985
ENTRYPOINT ["/entrypoint.sh"]

Dockerfile.openresty

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ STOPSIGNAL SIGQUIT
4747

4848
ENV PATH="$PATH:/opt/openresty/luajit/bin:/opt/openresty/nginx/sbin:/opt/openresty/bin"
4949

50-
EXPOSE 80
50+
EXPOSE 3128
5151

5252
CMD ["/opt/openresty/bin/openresty", "-g", "daemon off;"]

entrypoint.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ echo -n "" >/opt/openresty/nginx/conf/docker.intercept.map
4848
# Some hosts/registries are always needed, but others can be configured in env var REGISTRIES
4949
for ONEREGISTRYIN in docker.caching.proxy.internal registry-1.docker.io auth.docker.io ${REGISTRIES}; do
5050
ONEREGISTRY=$(echo ${ONEREGISTRYIN} | xargs) # Remove whitespace
51-
echo "${ONEREGISTRY} 127.0.0.1:443;" >>/opt/openresty/nginx/conf/docker.intercept.map
51+
echo "${ONEREGISTRY} 127.0.0.1:8443;" >>/opt/openresty/nginx/conf/docker.intercept.map
5252
done
5353

5454
# Clean the list and generate certificates.
@@ -90,8 +90,8 @@ if [ "$AUTH_REGISTRIES" ]; then
9090
done
9191
fi
9292

93-
# create default config for the caching layer to listen on 443.
94-
echo " listen 443 ssl default_server;" >/opt/openresty/nginx/conf/caching.layer.listen
93+
# create default config for the caching layer to listen on 8443.
94+
echo " listen 8443 ssl default_server;" >/opt/openresty/nginx/conf/caching.layer.listen
9595

9696
# Set Docker Registry cache size, by default, 32 GB ('32g')
9797
CACHE_MAX_SIZE=${CACHE_MAX_SIZE:-32g}
@@ -167,7 +167,7 @@ else
167167
return 405 "DELETE method is not allowed";
168168
}
169169
EOF
170-
if [ "$UPSTREAM_REGISTRIES" ]; then
170+
if [[ -v UPSTREAM_REGISTRIES ]]; then
171171
UPSTREAM_REGISTRIES_DELIMITER=${UPSTREAM_REGISTRIES_DELIMITER:-" "}
172172
s=$UPSTREAM_REGISTRIES$UPSTREAM_REGISTRIES_DELIMITER
173173
upstream_array=()

nginx.conf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
worker_processes auto;
22

3-
pid /var/run/nginx.pid;
3+
pid "/opt/openresty/nginx/tmp/nginx.pid";
44

55
events {
66
worker_connections 1024;
@@ -18,6 +18,12 @@ http {
1818
proxy_buffer_size 128k;
1919
proxy_buffers 4 256k;
2020

21+
client_body_temp_path "/opt/openresty/nginx/tmp/client_body" 1 2;
22+
proxy_temp_path "/opt/openresty/nginx/tmp/proxy" 1 2;
23+
fastcgi_temp_path "/opt/openresty/nginx/tmp/fastcgi" 1 2;
24+
scgi_temp_path "/opt/openresty/nginx/tmp/scgi" 1 2;
25+
uwsgi_temp_path "/opt/openresty/nginx/tmp/uwsgi" 1 2;
26+
2127
# Use a debug-oriented logging format.
2228
log_format debugging escape=json
2329
'{'
@@ -165,9 +171,8 @@ http {
165171

166172
# The caching layer
167173
server {
168-
# Listen on both 80 and 443, for all hostnames.
169-
# actually could be 443 or 444, depending on debug. this is now generated by the entrypoint.
170-
listen 80 default_server;
174+
# Listen on both 8080 and 8443, for all hostnames.
175+
listen 8080 default_server;
171176
include /opt/openresty/nginx/conf/caching.layer.listen;
172177
server_name proxy_caching_;
173178

0 commit comments

Comments
 (0)