首页 > 解决方案 > 不保留多 dockerfile 的权限

问题描述

对于上下文,我目前正在从自定义 Nginx docker 镜像(我也构建)构建一个 Flask docker 镜像。出于安全考虑,我正在尝试为图像使用非 root 用户。

第一个图像,nginx,工作正常。我正确安装了 nginx,我在某些文件夹上设置了正确的权限:

# Create needed users
RUN set -x && \
    useradd supervisor --uid 1001

# Setting needed permissions
RUN set -x && \
    rm -f /etc/nginx/conf.d/*.conf && \
    # logging for supervisor
    mkdir -p /var/log/supervisor && chown supervisor. -R /var/log/supervisor && \
    # PID Files
    touch /var/run/supervisord.pid && chown supervisor. /var/run/supervisord.pid && \
    touch /var/run/nginx.pid && chown supervisor. /var/run/nginx.pid && \
    # Cache dir permissions for nginx
    chown supervisor. -R /var/cache/nginx && \
    # Nginx configuration files
    chown supervisor. -R /etc/nginx

USER supervisor

构建和运行此映像完美运行,我可以看到(在容器内)一切正常:

37615352 4 -rw-r--r--. 1 supervisor supervisor 1007 Oct 29  2020 fastcgi_params
37615353 4 -rw-r--r--. 1 supervisor supervisor 2837 Oct 29  2020 koi-utf
37615354 4 -rw-r--r--. 1 supervisor supervisor 2223 Oct 29  2020 koi-win
37615355 8 -rw-r--r--. 1 supervisor supervisor 5231 Oct 29  2020 mime.types
37615356 0 lrwxrwxrwx. 1 supervisor supervisor   29 Oct 29  2020 modules -> ../../usr/lib64/nginx/modules
37615357 4 -rw-r-----. 1 supervisor supervisor  524 Aug 10 16:43 nginx.conf
37615369 4 -rw-r--r--. 1 supervisor supervisor  636 Oct 29  2020 scgi_params
37615370 4 -rw-r--r--. 1 supervisor supervisor  664 Oct 29  2020 uwsgi_params
37615371 4 -rw-r--r--. 1 supervisor supervisor 3610 Oct 29  2020 win-utf

现在我想构建我的新图像烧瓶,它继承自这个烧瓶,并且不触及 nginx 文件夹中的任何内容,这里会发生什么:

36588004 0 drwxr-xr-x. 1 root       root         26 Aug 10 17:09 conf.d
24718107 4 -rw-r--r--. 1 root       root       1007 May 25 13:41 fastcgi_params
24718110 8 -rw-r--r--. 1 root       root       5231 May 25 13:41 mime.types
24718111 0 lrwxrwxrwx. 1 root       root         29 May 25 13:41 modules -> ../../usr/lib64/nginx/modules
56775928 4 -rw-r-----. 1 supervisor supervisor  524 Aug 10 16:50 nginx.conf
24718112 4 -rw-r--r--. 1 root       root        648 May 25 13:30 nginx.conf.rpmnew
24718113 4 -rw-r--r--. 1 root       root        636 May 25 13:41 scgi_params
24718114 4 -rw-r--r--. 1 root       root        664 May 25 13:41 uwsgi_params

我只是在新映像上安装了烧瓶和 uwsgi,但是当我在构建后尝试运行它时,我看到以前设置的文件夹的权限以某种方式“重置”。

关于正在发生的事情有什么想法吗?提前致谢

标签: dockernginxbuildpermissions

解决方案


推荐阅读