nginx 如何允许只读根文件系统的容器写入tmpfs-volume?

qv7cva1a  于 2023-04-05  发布在  Nginx
关注(0)|答案(2)|浏览(165)

我有以下问题:
我的nginx容器是从只读的root-filesystem开始的,我配置了两个tmpfs-mounts:/var/run和/var/cache/nginx,就像那里描述的那样:https://hub.docker.com/_/nginx
在启动时,nginx抛出此错误,容器停止:2021/08/26 06:31:16 [emerg] 1#1:mkdir()“/var/cache/nginx/client_temp”失败(30:只读文件系统)
这是我的ecs task-config:

{ 
    "name": "nginx", 
    "essential": false,
    "readonlyRootFilesystem": true,
    "healthCheck": {
        "command": [
          "CMD-SHELL",
          "curl  --fail 127.0.0.1 || exit 1"
        ],
        "interval": 30,
        "timeout": 2,
        "retries": 3
      },
    "memory": 256,
    "image": "###########.dkr.ecr.eu-central-1.amazonaws.com/nginx:${NGINX_VER}",
    "dockerLabels":
      {
        "Name": "nginx",
        "Component": "sidecar-prometheus",
        "App-Version": "${NGINX_VER}"
      },
    "logConfiguration": {
      "logDriver": "awslogs",
      "options": {
         "awslogs-group": "${LOG_GROUP_NAME}",
         "awslogs-region": "eu-central-1",
         "awslogs-stream-prefix": "${LOG_GROUP_NAME}"
      }
    },
    "portMappings": [
      {
        "containerPort": 10000,
        "hostPort": 10000,
        "protocol": "tcp"
      }
    ],  
    "mountPoints": [
      {
        "readOnly": false,
        "containerPath": "/config",
        "sourceVolume": "VolumeConfig"
      }
    ],
    "tmpfs": {
        "containerPath": "/var/run",
        "size": "50",
        "mountOptions": "rw"
    },
    "tmpfs": {
        "containerPath": "/var/cache/nginx",
        "size": "50",
        "mountOptions": "rw"
    },

如何让/var/cache/nginx挂载rw?
非常感谢您的帮助!

lxkprmvk

lxkprmvk1#

答案是配置错误!
下面是正确的方法,tmpfs必须包含在linuxParameters中:

"linuxParameters": {
    "tmpfs": [
      {
        "containerPath": "/var/log/nginx",
        "mountOptions": [ "rw" ],
        "size": 50
      },
      {
        "mountOptions": [ "rw" ],
        "containerPath": "/run",
        "size": 10
      },
      {
        "mountOptions": [ "rw"],
        "containerPath": "/var/cache/nginx",
        "size": 10
      },
      {
        "mountOptions": [ "rw"],
        "containerPath": "/tmp",
        "size": 10
      }
    ]
    }
rslzwgfq

rslzwgfq2#

查看documentationtmpfs接受Array of Tmpfs objects
你似乎传递了tmpfs两次,而不是传递一个数组。正确传递一个数组应该可以工作:

"tmpfs": [
      {
        "containerPath": "/var/run",
        "size": "50",
        "mountOptions": "rw"
      },
      {
        "containerPath": "/var/cache/nginx",
        "size": "50",
        "mountOptions": "rw"
      }
    ]

相关问题