【问题标题】:In Fedora 31 how do I set permissions for nginx running in a Podman container?在 Fedora 31 中,如何为 Podman 容器中运行的 nginx 设置权限?
【发布时间】:2020-11-05 02:58:06
【问题描述】:

我正在尝试使用 podman-compose 为 Slim-4 项目设置本地开发 LEMP 堆栈。到目前为止,我有 PHP 和 Nginx 的容器。 Nginx 运行但在尝试访问日志目录时出现 500 错误 - 权限被拒绝。该目录位于 nginx 服务的公共目录之外。

我已将 selinux 设置为 permissive 以消除其问题。 我使用 podman unshare 将所有权设置为容器的 Nginx UID:GID。 我只用一个简单的索引文件尝试了设置——该文件没有问题。因此,nginx/podman 可以访问主机上的 nginx 配置文件。问题一定是写权限。

这是我的 docker-compose 文件:

version: '3.7'

# Services
services:

# Nginx Service
nginx:
  image: nginx:1.17
  ports:
    - 8090:80
  volumes:
    - .:/var/www/php:z
    - ./.docker/nginx/conf.d:/etc/nginx/conf.d:ro
  depends_on:
    - php

# PHP Service
php:
  image: php:7.4-fpm
  working_dir: /var/www/php
  volumes:
    - .:/var/www/php

我错过了什么?

【问题讨论】:

    标签: permissions fedora selinux podman slim-4


    【解决方案1】:

    问题是我错误地认为我需要设置权限以允许 Nginx 访问。 相反,我需要授予组 www-data 访问权限。
    我是怎么做到的:
    登录到正在运行的 Nginx 容器 podman exec -it [container ID] bash
    找到 www-data GID(组 ID) - 从容器命令行,cat /etc/passwd | grep www-data
    请注意 GID(在结果中您会看到类似 ...x:33:33... 33:33 是用户:组)
    使用 exit 退出容器 cli
    在您的开发/主机 cli 中,在项目的根目录下,运行 podman unshare chown -R 0:[the www-data GID you found above] . (不要错过 '.')

    说明:
    podman unshare puts您在与容器匹配的修改用户空间中
    chown 更改所有权
    -R 表示递归
    ':' 左边的数字是 UID(用户 ID),右边的数字是 GID
    这 '。'是当前目录。

    我希望这对某人有所帮助。我花了几个小时学习上述内容。

    【讨论】:

    猜你喜欢
    • 2021-03-04
    • 2021-05-02
    • 1970-01-01
    • 2022-01-20
    • 2021-04-28
    • 2020-12-08
    • 2019-09-25
    • 1970-01-01
    • 2017-09-14
    相关资源
    最近更新 更多