Docker-nginx: /etc/nginx/conf.d/default.conf differs from the packaged version, exiting

Created on 3 Jun 2020  ·  12Comments  ·  Source: nginxinc/docker-nginx

Hello, I am trying to setup Rails application with ngnix, but no matter what I do I am always getting this error: nginx_1 | 10-listen-on-ipv6-by-default.sh: /etc/nginx/conf.d/default.conf differs from the packaged version, exiting when using: sudo docker-compose -f docker-compose.prod.yml up command any similar.

My Dockerfile-nginx:

FROM nginx:1.19.0

RUN apt-get update -qq && apt-get -y install apache2-utils

ENV RAILS_ROOT /var/www/app

WORKDIR $RAILS_ROOT

RUN mkdir log

COPY public public/

# When I try to pass config using Copy the same error happens, I prefer using compose volume.
# COPY config/containers/ssl/default.conf /tmp/docker.nginx
# RUN envsubst '$RAILS_ROOT' < /tmp/docker.nginx > /etc/nginx/conf.d/default.conf

EXPOSE 80 443

CMD [ "nginx", "-g", "daemon off;" ]

docker-compose.prod.yml:

version: '2'

services:
  mysql:
    image: 'mysql:5.7'
    environment:
      ...
    ports:
      - "3307:3306"

  redis:
    image: 'redis:3.2.1-alpine'
    command: redis-server
    volumes:
      - 'redis:/data'

  website:
    depends_on:
      - 'mysql'
      - 'redis'
      - 'sidekiq'
    build: .
    ports:
      - '3000:3000'
    environment:
      RAILS_ENV: production
    env_file: .env

  sidekiq:
    depends_on:
      - 'mysql'
      - 'redis'
    build: .
    command: bundle exec sidekiq
    volumes:
      - '.:/website'
    environment:
      REDIS_URL: redis://redis:6379/0

  nginx:
    build:
      context: .
      dockerfile: ./config/containers/Dockerfile-nginx
    volumes:
      - ./config/containers/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - website
    ports:
      - "80:80"


volumes:
  redis:
  mysql:

And default.conf:

server {
  listen 80;
}

Anyone is having any idea why it happen? I've tried everything what comes to my mind to fix it. I wonder how the Conffiles are generated as it seems to be the source of the issue: https://github.com/nginxinc/docker-nginx/blob/master/mainline/alpine/10-listen-on-ipv6-by-default.sh

Most helpful comment

@thresheek sorry just an opinion, because I do not know if you have a policy governing these things, but then it is not really an error. it is just an "info". I also ran into this and when I saw the word "error" I automatically thought I have made a mistake in the configuration.

All 12 comments

Hello,

That means the 10-listen-on-ipv6-by-default.sh exits, not the container itself. I guess I should update the wording to avoid confusion.

Hello,

That means the 10-listen-on-ipv6-by-default.sh exits, not the container itself. I guess I should update the wording to avoid confusion.

how to resolve?

[root@iZ4kgzm2ne37e4Z ~]# docker logs -f nginx-app 
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: error: /etc/nginx/conf.d/default.conf differs from the packaged version
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
59.127.181.169 - - [29/Jul/2020:02:18:57 +0000] "GET / HTTP/1.1" 400 157 "-" "-" "-"
118.232.208.156 - - [29/Jul/2020:02:19:02 +0000] "GET / HTTP/1.1" 400 157 "-" "-" "-"
220.135.250.221 - - [29/Jul/2020:02:19:06 +0000] "GET / HTTP/1.1" 400 157 "-" "-" "-"

i don't like the error

10-listen-on-ipv6-by-default.sh: error: /etc/nginx/conf.d/default.conf differs from the packaged version

the /etc/nginx/conf.d/default.conf

server {  
    listen 80; 
    listen [::]:80;
    server_name nginx.mydemo.com;

    # Redirect all HTTP requests to HTTPS  
    location / {  
        return 301 https://;  
    }  
}

server {  
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name nginx.mydemo.com;

    ssl_certificate            /etc/ssl/self/nginx-selfsigned.crt;  
    ssl_certificate_key        /etc/ssl/self/nginx-selfsigned.key;
    ssl_protocols       TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_dhparam /etc/ssl/self/dhparam.pem;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

run docker

docker run -d --name nginx-app \
  --restart always \
  -p 80:80 -p 443:443 \
  -v /etc/nginx/nginx.conf:/etc/nginx/conf.d/default.conf:rw \
  -v /etc/nginx/ssl:/etc/ssl/self \
  nginx  

@thresheek

That's normal when you have default.conf differing from what we package. We delibarately would not change it to enable ipv6. (in your case, its already enabled). You can suppress error messages with NGINX_ENTRYPOINT_QUIET_LOGS variable in your docker container environment configuration.

@thresheek sorry just an opinion, because I do not know if you have a policy governing these things, but then it is not really an error. it is just an "info". I also ran into this and when I saw the word "error" I automatically thought I have made a mistake in the configuration.

I dont like when it say the error on this case.

Hello all,

I ve raised an issue related to this issue here... I m lost... connection between the host and my backend working like a charmed.

My conf file was working before I ve redeployed my Nginx container...
The conf file is well pointed (checked via docker exec)

When I change the name from default.conf to xxx.conf (before named xxx.conf , and suddenly error as no default.conf was located....)

The message is the following:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: error: /etc/nginx/conf.d/default.conf differs from the packages version
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

However the service seems not running and not lin with my backend anymore....

Needs your support please!

I found the error in my case ! My non working nginx config had this line:

fastcgi_pass php:9000;

and the problem was that php seems to a hostname here, but nginx box couldnt find another docker box reachable with the name php.

But this works: Rename the PHP docker box to something different like

  php-box1:
    container_name: php-box1

and change the nginx config accordingly

# this needs to be the docker container name of PHP and :9000
fastcgi_pass php-box1:9000;

I am experiencing the same problem in a service run as docker swarm (docker stack deploy)
the error was "No route to host", after surfing and searching I found that nginx service was ready before the companion service (php fpm), I just stopped the container and the swarm controller restart a new one, this fixed the problem.
I have no idea on how to solve this (there is a solution in docker.com site, actually), but I think it is not correct this upfront resolution of ip address in a docker environment.

I mean, why nginx resolve address name once at start and not ask for resolver every time? If I had removed the service then deployed it again that would have not worked, because the nginx resolved with the old service address that changes everytime a service is restarted.

maybe https://medium.com/driven-by-code/dynamic-dns-resolution-in-nginx-22133c22e3ab would work?
I paste it here:

location / {
    resolver 10.0.0.2;
set $elb_dns internal-balancer-loader-2000–1525531520.us-west-2.elb.amazonaws.com;
proxy_pass $elb_dns;
}

(my case is fastcgi_pass), the author say "Nginx evaluates the value of the variable per-request, instead of just once at startup.", and it is workaround way

I'd also like to vote to change the message from 'error' to 'info' or something like that. 👍

My vote too!!

echo >&3 "$ME: error: ipv6 not available"

echo >&3 "$ME: error: /$DEFAULT_CONF_FILE is not a file or does not exist"

These should be info as well yes?

Voting to change the wording from error to info as well.
Errors are of catastrophic nature. Warnings or infos are just that, warnings/information... warn is also acceptable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

colinmollenhour picture colinmollenhour  ·  6Comments

ralphsmith80 picture ralphsmith80  ·  5Comments

lucacome picture lucacome  ·  3Comments

a-shink picture a-shink  ·  3Comments

lrhazi picture lrhazi  ·  3Comments