I am using nginx:1.10.1-alpine to run Nginx as a docker container. Today I have replaced the Nginx container and always got the status Restarting (1) Less than a second ago after starting the container.
1 2 |
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES aadc6336a026 docker_nginx "nginx -g 'daemon off" 10 minutes ago Restarting (1) Less than a second ago 0.0.0.0:80->80/tcp, 443/tcp nginx |
With the command docker logs nginx I got the following error logs.
1 2 3 4 5 6 |
2016/09/10 22:58:49 [emerg] 1#1: getpwnam("www-data") failed in /etc/nginx/nginx.conf:1 nginx: [emerg] getpwnam("www-data") failed in /etc/nginx/nginx.conf:1 2016/09/10 22:58:50 [emerg] 1#1: getpwnam("www-data") failed in /etc/nginx/nginx.conf:1 nginx: [emerg] getpwnam("www-data") failed in /etc/nginx/nginx.conf:1 2016/09/10 22:58:50 [emerg] 1#1: getpwnam("www-data") failed in /etc/nginx/nginx.conf:1 nginx: [emerg] getpwnam("www-data") failed in /etc/nginx/nginx.conf:1 |
The error message basically means that the user www-data which I have defined in /etc/nginx/nginx.conf doesn’t exists in /etc/passwd. That makes sense, because nginx:1.10.1-alpine comes with a minimal setup. I my case I need the user www-data for other linked php-fpm containers. To fix the problem I just added the missing user during the container build.
1 2 3 |
FROM nginx:1.10.1-alpine RUN addgroup -g 1000 -S www-data \ && adduser -u 1000 -D -S -G www-data www-data |
Voilà.
1 2 3 4 5 6 7 8 |
Building nginx Step 1 : FROM nginx:1.10.1-alpine ---> c07e2bb859e2 Step 2 : RUN addgroup -g 1000 -S www-data && adduser -u 1000 -D -S -G www-data www-data ---> Running in c1cd75c7dc52 ---> 83528539d9c9 Removing intermediate container c1cd75c7dc52 Successfully built 83528539d9c9 |
Consider this a upvote! 😉
thank you
Still a help here in 2018. Thank you.