【发布时间】:2021-04-09 11:54:13
【问题描述】:
我有来自 nginx 映像的带有 myuser 的 Dockerfile,我想在已安装的位置挂载日志,我正在使用 docker-compose 来启动容器。我的要求是只使用非 root 用户而不使用 sudo。
我的 dockerfile 和 myuser,我创建的图像标签是 mynginx:v1
RUN addgroup mygroup
RUN adduser myuser --disabled-password
USER myuser
非工作 docker compose with mynginx image with myuser
version: "2"
services:
nginx:
container_name: nginx
image: mynginx:v1
ports:
- "8888:80"
volumes:
- ./log/nginx:/var/log/nginx
虽然目录已挂载,但在主机上看不到 nginx 日志文件 access.log 和 error.log。
Docker 日志如下:
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2021/04/09 12:46:08 [warn] 1#1: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2
2021/04/09 12:46:08 [emerg] 1#1: mkdir() "/var/cache/nginx/client_temp" failed (13: Permission denied)
但是,如果我对以 root 用户身份运行的官方 nginx 映像执行相同操作,则一切正常。
使用 root 用户使用官方 nginx 映像工作的 docker compose
version: "2"
services:
nginx:
container_name: nginx
image: nginx
ports:
- "8888:80"
volumes:
- ./log/nginx:/var/log/nginx
尝试查看各种选项,但到目前为止没有运气。
【问题讨论】:
-
您能否在 docker 之外使用与容器用户相同的 uid 写入该目录?
标签: docker