Search code examples
nginxpermissionsdockerlsalpine-linux

nginx alpine docker fails without previous ls?


I want to use radicale with nginx inside a alpine based docker file. I am currently develop the Dockerfile and noticed a really strange behaivor, maybe somebody can explain this to me.

  1. build image

https://gist.github.com/cdpb/7ab1690f30fe6a911dac

  1. docker run -it <id> sh
  2. su radicale -c 'nginx -t'

:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] mkdir() "/var/lib/nginx/tmp/client_body" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
  1. ls -l /var/lib/nginx/tmp

:

total 20
drwxr-xr-x    2 radicale radicale      4096 Feb 17 11:39 client_body
drwxr-xr-x    2 radicale radicale      4096 Feb 17 11:39 fastcgi
drwxr-xr-x    2 radicale radicale      4096 Feb 17 11:39 proxy
drwxr-xr-x    2 radicale radicale      4096 Feb 17 11:39 scgi
drwxr-xr-x    2 radicale radicale      4096 Feb 17 11:39 uwsgi
  1. su radicale -c 'nginx -t'

:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

so what happens after the ls? it should not affect any permissions ... !? Can somebody reproduce this?

Regards

cdpb

UPDATE1: works also with stat /var/lib/nginx/tmp/*

UPDATE2: because docker creates a new layer for every command in Dockerfile, I thought that nginx has to be started within the same layer as the chmod/chown layer - didn't fix the problem

UPDATE3: I did the same with a disk installed alpine ( virtualbox ) and the problem didn't occur. So it's more a docker related problem or a special alpine docker one


Solution

  • Moving my answer from the comments.

    Such weirdness is usually related to a Docker storage driver.

    There are usually several available Docker storage drivers available on most OSes:

    • AUFS (available and default in Ubuntu, Boot2Docker, and also available in Debian testing) - while, AFAIK, it was historically the first FS driver in Docker, AUFS is not part of mainline Linux kernel, so it is not widely adopted.
    • OverlayFS - mainline Linux kernel closest alternative to AUFS
    • Device Mapper - the slowest, but the most portable Docker storage driver
    • etc...

    Here is a nice picture comparing different storage drivers from the link posted above.

    Pros and Cons of Docker storage drivers