简体   繁体   English

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

[英]How to allow Container with read only root filesystem writing to tmpfs-volume?

i have the following problem:我有以下问题:

my nginx container is starting with read only root-filesystem and i have configured two tmpfs-mounts: /var/run and /var/cache/nginx like it's described there: https://hub.docker.com/_/nginx我的 nginx 容器以只读根文件系统开始,我已经配置了两个 tmpfs-mounts:/var/run 和 /var/cache/nginx 就像那里描述的那样: https://hub.docker.com/_/nginx

At startup nginx throws this error and the container stops: 2021/08/26 06:31:16 [emerg] 1#1: mkdir() "/var/cache/nginx/client_temp" failed (30: Read-only file system)在启动时 nginx 抛出此错误并且容器停止: 2021/08/26 06:31:16 [emerg] 1#1: mkdir() "/var/cache/nginx/client_temp" failed (30: Read-only file system )

This is my ecs task-config:这是我的 ecs 任务配置:

{ 
    "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"
    },

How can i make the /var/cache/nginx mount rw?我怎样才能让 /var/cache/nginx 挂载 rw?

Many thanks for helping !非常感谢您的帮助!

The answer is that the config was wrong !答案是配置错误!

Here is the right way, tmpfs must include in linuxParameters:这是正确的方法,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
      }
    ]
    }

Looking at the documentation , tmpfs accepts Array of Tmpfs objects .查看文档tmpfs接受Array of Tmpfs objects

You seem to be passing tmpfs twice, instead of passing an array.您似乎两次传递tmpfs ,而不是传递一个数组。 Passing an array properly should work:正确传递数组应该有效:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当根文件系统为只读时如何将证书添加到 POD/Container 的证书库 - how to add certificate to POD/Container 's cert store when root filesystem is read-only 如何在 Cloud Run 中部署带卷的 docker 容器 - How to Deploy a docker container with volume in Cloud Run 如何将 ebs 卷(或部分)挂载到 Fargate 容器 - How to mount ebs volume(or part) to fargate container 如何调整 windows ec2 根卷的大小 (c) - how to resize windows ec2 root volume (c) Kubernetes:无法将未格式化的卷挂载为只读 - Kubernetes: failed to mount unformatted volume as read only 如何在运行时更改 AWS Batch 的根卷大小 - How do I change root volume size of AWS Batch at runtime 如何只允许少数 IP 访问 AWS 网络负载均衡器? - How to only allow a few IPs to reach a AWS Network Load Balancer? 从 API 创建 Ec2 时扩展根卷 - Expand Root Volume when Creating Ec2 from API AWS Batch:使用云形成将 efs 卷装载到容器中 - AWS Batch: mount an efs volume into a container using cloud formation Firestore 安全规则:只允许只读作者规则不起作用 - Firestore Security Rule: Allow read only for Author rule not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM