本文介绍了ECS任务定义是否支持卷映射语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务下的

docker-compose规范支持卷映射语法,例如:

docker-compose spec support volume mapping syntax under services, for example:

version: '2'

volumes:
  jenkins_home:
    external: true

services:
  jenkins:
    build:
      context: .
      args:
        DOCKER_GID: ${DOCKER_GID}
        DOCKER_VERSION: ${DOCKER_VERSION}
        DOCKER_COMPOSE: ${DOCKER_COMPOSE}
    volumes:
      - jenkins_home:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - "8080:8080"


"AWSTemplateFormatVersion":"2010-09-09" 之后,相应的ECS任务定义的卷语法不可读(和 Volumes ),如下所示:


Following "AWSTemplateFormatVersion": "2010-09-09", the corresponding ECS task definition has volume syntax un-readable(with MountPoints and Volumes), as shown below:

"EcsTaskDefinition": {
            "Type": "AWS::ECS::TaskDefinition",
            "Properties": {
                "ContainerDefinitions": [
                    {
                        "Name": "jenkins",
                        "Image": "xyzaccount/jenkins:ecs",
                        "Memory": 995,
                        "PortMappings": [ { "ContainerPort": 8080, "HostPort": 8080 } ],
                        "MountPoints": [
                            {
                                "SourceVolume": "docker",
                                "ContainerPath": "/var/run/docker.sock"
                            },
                            {
                                "SourceVolume": "jenkins_home",
                                "ContainerPath": "/var/jenkins_home"
                            }
                        ]
                    }


                ],
                "Volumes": [
                    {
                        "Name": "jenkins_home",
                        "Host": { "SourcePath": "/ecs/jenkins_home" }
                    },
                    {
                        "Name": "docker",
                        "Host": { "SourcePath": "/var/run/docker.sock" }
                    }
                ]
            }
        }


CloudFormation(现在)的ECS任务定义语法是否支持卷映射语法?类似于docker-compose ....


Does ECS task definition syntax of CloudFormation (now) support volume mapping syntax? similar to docker-compose....

推荐答案

是的,当然,ECS支持docker socket挂载,但是语法略有不同.在任务定义中添加 DOCKER_HOST 环境变量,源路径应以//开头.

Yes, of course, ECS support docker socket mounting, but the syntax is bit different. Add DOCKER_HOST environment variable in the task definition and source path should start with //.

 "volumes": [
        {
            "name": "docker",
            "host": {
                "sourcePath": "//var/run/docker.sock"
            }
        }
    ]

//在AWS ecs的情况下有效.

The // worked in case of AWS ecs.

此外,您还需要在任务定义中添加 DOCKER_HOST 环境变量.

Also, you need to add DOCKER_HOST environment variable in your task definition.

            "environment": [
                {
                    "name": "DOCKER_HOST",
                    "value": "unix:///var/run/docker.sock"
                }
            ]

这篇关于ECS任务定义是否支持卷映射语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 07:05