linux - 如何以非 root 用户身份运行 nginx 容器?

标签 linux docker nginx permissions containers

每次我尝试以非 root 用户身份运行容器时,都会出现以下错误:

 the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
Dockerfile:
FROM nginx:1.17.6
RUN chown -R nginx:nginx /var/cache/nginx && \
        chown -R nginx:nginx /var/log/nginx && \
        chown -R nginx:nginx /etc/nginx/conf.d
RUN chmod -R 777 /etc/nginx/conf.d

USER nginx

COPY app/build /usr/share/nginx/html

RUN rm /etc/nginx/conf.d/default.conf

COPY nginx/nginx.conf /etc/nginx/conf.d


CMD ["nginx","-g","daemon off;"]

最佳答案

使用来自 nginx 的无根 docker-imager。
图片

nginxinc/nginx-unprivileged  
DockerHub
https://hub.docker.com/r/nginxinc/nginx-unprivileged
GitHub
https://github.com/nginxinc/docker-nginx-unprivileged

关于linux - 如何以非 root 用户身份运行 nginx 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63108119/

相关文章:

nginx - 连接上游时没有实时上游,但上游是可以的

bash - 尝试 cURL 松弛时获取无效负载

linux - 一个一个执行三个可执行文件

python - 使用 Dockerfile 安装 MongoDB 和 Tomcat

c - 使用 libsqlite3 的间歇性段错误, "error 4 in libsqlite3.so.0.8.6"

docker - 将 ARG 从 docker-compose.yml 传递到 docker 镜像

php - Apache 404 文件匹配

node.js - 如何使用 nginx 反向代理和 https 获取 socket.io 示例

linux - 在 linux 中使用命令行检查单个线程优先级

linux - 在 morty : backtrace-supported. h 中构建 libgfortran_6.2.bb 配方时出错:没有这样的文件或目录