S
S
SantyagoNN2019-02-06 13:58:12
Nginx
SantyagoNN, 2019-02-06 13:58:12

Docker + Nginx getpwnam("www-data") problem how to solve?

In Dockerfile

#nginx
FROM nginx:alpine
RUN touch /var/run/nginx.pid && \
    chown -R www-data:www-data /var/run/nginx.pid && \
    chown -R www-data:www-data /var/cache/nginx
USER www-data
VOLUME /var/www
...

in nginx.conf
user www-data;
pid /var/run/nginx.pid;
...

In docker-compose.yml
...
  #Nginx Service
  nginx:
        image: nginx:alpine
        container_name: nginx
        restart: unless-stopped
        tty: true
        ports:
          - "80:80"
          - "443:443"
        volumes:
          - ./www:/var/www
          - ./nginx/:/etc/nginx/
          - ./log/nginx/:/var/log/nginx/
          - ./opt/:/opt/
        networks:
          - app-network
...

During startup in nginx logs:
2019/02/06 10:59:09 [emerg] 1#1: getpwnam("www-data") failed in /etc/nginx/nginx.conf:1

Exhausted... Help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sash999, 2019-02-06
@sash999

You don't have such a user - www-data. And the groups too. Add something like this to your Dockerfile:
RUN addgroup -g 1010 -S www-data && adduser -u 1010 -D -S -G www-data www-data

S
SantyagoNN, 2019-02-06
@SantyagoNN

added, same problem

#nginx
FROM nginx:alpine
RUN addgroup -g 1010 -S www-data && \
    adduser -u 1010 -D -S -G www-data www-data && \
    touch /var/run/nginx.pid && \
    chown -R www-data:www-data /var/run/nginx.pid && \
    chown -R www-data:www-data /var/cache/nginx
USER www-data
VOLUME /var/www

2019/02/06 13:28:34 [emerg] 1#1: getpwnam("www-data") failed in /etc/nginx/nginx.conf:1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question