我使用的是Docker Hub的官方nginx镜像:https://hub.docker.com/_/nginx/
nginx (在/etc/nginx/nginx.conf中定义)的用户是nginx。有没有办法让nginx在不扩展docker镜像的情况下以www-data的身份运行?这样做的原因是,我有一个共享卷,它由多个容器使用-我以www-data和nginx的身份运行的php-fpm。共享卷中文件/目录的所有者是www-data:www-data,而nginx在访问该文件/目录时遇到问题-错误类似于*1 stat() "/app/frontend/web/" failed (13: Permission denied)
我有一个docker-compose.yml,可以运行我所有的容器,包括带有docker-compose up的nginx容器。
...
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./:/app
- ./vhost.conf:/etc/nginx/conf.d/vhost.conf
links:
- fpm
...发布于 2016-04-28 15:39:10
仅供参考
的问题
做什么?
修复你的php-fpm容器,不要破坏好的nginx容器。
解决方案
https://stackoverflow.com/a/36130772/1032085
从php:5.6-fpm运行usermod -u 1000 www-data
发布于 2019-07-14 07:06:08
我知道OP要求一个不扩展nginx镜像的解决方案,但是我在这里没有这个限制。因此,我将此Dockerfile设置为以www-data:www-data (33:33)身份运行nginx:
FROM nginx:1.17
# Customization of the nginx user and group ids in the image. It's 101:101 in
# the base image. Here we use 33 which is the user id and group id for www-data
# on Ubuntu, Debian, etc.
ARG nginx_uid=33
ARG nginx_gid=33
# The worker processes in the nginx image run as the user nginx with group
# nginx. This is where we override their respective uid and guid to something
# else that lines up better with file permissions.
# The -o switch allows reusing an existing user id
RUN usermod -u $nginx_uid -o nginx && groupmod -g $nginx_gid -o nginx在映像构建期间,它在命令行上接受uid和gid。要制作一个以当前用户id和组id运行的nginx镜像,例如:
docker build --build-arg nginx_uid=$(id -u) nginx_uid=$(id -g) .nginx用户和组in目前在镜像中为hardcoded to 101:101。
发布于 2020-09-15 20:05:26
另一种选择是从https://github.com/nginxinc/docker-nginx获取源代码,并更改docker文件以支持构建参数Ex:更改buser release (https://github.com/nginxinc/docker-nginx/blob/master/stable/buster/Dockerfile)的稳定docker文件。将nginx用户/组uid/gid设置为构建参数
FROM debian:buster-slim
LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>"
ENV NGINX_VERSION 1.18.0
ENV NJS_VERSION 0.4.3
ENV PKG_RELEASE 1~buster
#Change NGNIX guid/uid#
ARG nginx_guid=101
ARG nginx_uid=101
RUN set -x \
# create nginx user/group first, to be consistent throughout docker variants
&& addgroup --system --gid $nginx_guid nginx \
&& adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid $nginx_uid nginx \这种方式比只使用usermod更安全,因为如果在chown nginx:nginx等其他位置执行某些操作,它将使用GUID/UID集
https://stackoverflow.com/questions/36824222
复制相似问题