在 Dockerfile 上以非 root 用户身份运行 nginx

在 Dockerfile 上以非 root 用户身份运行 nginx

我创建了以下 Dockerfile,以使用非 root 用户运行我的 Nginx 服务。但是,当我运行我创建的 docker 镜像并查看我的 docker 日志时,我收到以下错误。

2020-10-14T11:52:04.831656127Z nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2020-10-14T11:52:04.831687644Z 2020/10/14 11:52:04 [warn] 1#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:5
2020-10-14T11:52:04.832768412Z 2020/10/14 11:52:04 [emerg] 1#0: mkdir() "/var/lib/nginx/tmp/client_body" failed (13: Permission denied)
FROM registry.access.redhat.com/ubi8/ubi8-minimal
USER root 
RUN microdnf --setopt=tsflags=nodocs install -y nginx procps shadow-utils net-tools ca-certificates dirmngr gnupg wget vim\
            && microdnf clean all \
            && rpm -q procps-ng
RUN useradd -ms /bin/bash proxy

RUN mkdir -p /var/log/nginx
RUN mkdir -p /var/lib/nginx/ 

RUN chown proxy /var/log/nginx
RUN chown proxy /var/lib/nginx/ 

USER proxy 
WORKDIR /home/proxy

#COPY nginx.conf /etc/nginx/nginx.conf
RUN chmod 755 /home/proxy
#To start up NGINX 
EXPOSE 80
USER proxy
CMD ["nginx", "-g", "daemon off;"]

相关内容