TheCoder
TheCoder

Reputation: 89

How to Run nginx in docker as non-root user

One way to get this done is : http://pjdietz.com/2016/08/28/nginx-in-docker-without-root.html

With this approach we need to know or force to run nginx with USER name specified in Dockerfile.

But, nginx docker container is created as part of swarm(service) with a specific user name, which I don't know in advance. So specifying USER name in Dockerfile is not an option.. How to run nginx in a docker service under a specified user which is not known in advance.?

Upvotes: 2

Views: 6248

Answers (2)

kuklei
kuklei

Reputation: 1205

check this out https://forums.docker.com/t/running-nginx-official-image-as-non-root/135759/7

# Stage 2: Serve the app with Nginx with Brotli support
FROM wokalek/nginx-brotli:1.27.1
# FROM nginx:alpine #does not feature brotli support

# Install curl that we can use for health checks
# in the same step also apply permissions
RUN apk update && apk add curl && mkdir -p /var/log/nginx && \
    chown -R nginx:nginx /var/log/nginx && \
    chmod -R 755 /var/log/nginx && \
    mkdir -p /var/cache/nginx && \
    chown -R nginx:nginx /var/cache/nginx && \
    chown -R nginx:nginx /etc/nginx && \
    chmod -R 755 /etc/nginx

RUN touch /var/run/nginx.pid && \
        chown -R nginx:nginx /var/run/nginx.pid /run/nginx.pid

Upvotes: 0

mkorbi
mkorbi

Reputation: 247

Have you tried to run the non-root image from Nginx Inc.? https://github.com/nginxinc/docker-nginx-unprivileged

Upvotes: 4

Related Questions