【发布时间】:2021-01-31 01:25:00
【问题描述】:
我目前在尝试设置新用户而不是在我的 docker 文件中使用 root 时遇到了问题。图像构建良好,但是当我运行容器时出现以下错误: nginx: [emerg] mkdir() "/var/lib/nginx/tmp/client_body" failed (13: Permission denied)
下面是我的 dockerfile。我正在使用 redhat UBi 映像构建我的 dockerfile:
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
ENV NGINX_USER="api-gatway" \
NGINXR_UID="8987" \
NGINX_GROUP="api-gatway" \
NGINX_GID="8987"
RUN set -ex; \
groupadd -r --gid "$NGINX_GID" "$NGINX_GROUP"; \
useradd -r --uid "$NGINXR_UID" --gid "$NGINX_GID" "$NGINX_USER"
COPY nginx.conf /etc/nginx/nginx.conf
#To start up NGINX
EXPOSE 80
RUN mkdir -p /var/lib/nginx/
RUN mkdir -p /var/log/nginx/
RUN mkdir -p /var/lib/nginx/tmp/
RUN chmod 755 api-gatway:api-gatway /var/lib/nginx/
RUN chmod 755 api-gatway:api-gatway /var/log/nginx/
EXPOSE 80
USER api-gatway
CMD ["nginx", "-g", "daemon off;"]
任何想法为什么这仍然不起作用?
【问题讨论】:
-
它真的可以构建吗?
chmod似乎与chown混淆了。而且为什么不用nginx镜像呢? -
对不起,我取出了 chown 命令并用 chmod 替换了它,图像确实建立了,但运行它会给我上述错误。由于工作需要,必须使用redhat image
-
chmod +x /var/lib/nginx -R
标签: bash docker nginx permissions dockerfile