Kaniko: Running `nginx -t` causes "no such..." error

Created on 22 May 2020  路  3Comments  路  Source: GoogleContainerTools/kaniko

Actual behavior
With kaniko, running the nginx -t command produces either a No such file or directory or No such device or address error, even with an official, unmodified NGINX image. This does not happen with Docker.

Expected behavior
The nginx -t should not produce an error if the configuration file is valid.

To Reproduce

  1. Attempt to build the Dockerfile below
  2. Receive the following output:
INFO[2020-05-22T16:58:28Z] Running: [/bin/sh -c nginx -t;]              
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2020/05/22 16:58:28 [emerg] 25#25: open() "/var/run/nginx.pid" failed (2: No such file or directory)
nginx: [emerg] open() "/var/run/nginx.pid" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1

Additional Information

  • Dockerfile
FROM nginx:alpine
RUN nginx -t
  • Build Context
    No files other than the Dockerfile.

Sometimes we receive the following error, depending on NGINX's configuration:

INFO[2020-05-22T16:38:21Z] Running: [/bin/sh -c nginx -t;]              
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (6: No such device or address)
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2020/05/22 16:38:21 [emerg] 134#134: open() "/dev/stderr" failed (6: No such device or address)
nginx: configuration file /etc/nginx/nginx.conf test failed
error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1

Triage Notes for the Maintainers

| Description | Yes/No |
|----------------|---------------|
| Please check if this a new feature you are proposing |

  • - [ ]
|
| Please check if the build works in docker but not in kaniko |
  • - [x]
|
| Please check if this error is seen when you use --cache flag |
  • - [x]
|
| Please check if your dockerfile is a multistage dockerfile |
  • - [ ]
|

kinquestion more-information-needed prioritp3

Most helpful comment

This worked for me:

FROM nginx:alpine
RUN test -e /var/run || ln -s /run /var/run
RUN nginx -t

Seems like the /var/run -> /run symlink is not extracted from the base image rootfs due to the path being ignored by default.

docker run \
   -v $PWD:/workspace \
   gcr.io/kaniko-project/executor:latest \
  --dockerfile /workspace/Dockerfile \
  --context dir:///workspace/ \
  --no-push

All 3 comments

I saw a related bug here https://github.com/nginxinc/nginx-amplify-agent/issues/166
I am not sure if you can run a nginx service inside a kaniko pod. Is there something else you want to do after running the nginx service?

NGINX runs without issue in the container built by either kaniko or Docker, it's just the nginx -t command that fails in kaniko exclusively. Does that answer your question?

This worked for me:

FROM nginx:alpine
RUN test -e /var/run || ln -s /run /var/run
RUN nginx -t

Seems like the /var/run -> /run symlink is not extracted from the base image rootfs due to the path being ignored by default.

docker run \
   -v $PWD:/workspace \
   gcr.io/kaniko-project/executor:latest \
  --dockerfile /workspace/Dockerfile \
  --context dir:///workspace/ \
  --no-push
Was this page helpful?
0 / 5 - 0 ratings