阅读背景:

如何将docker-compose.yml翻译为Django的Dockerrun.aws.json

来源:互联网 

I am following the instructions at https://docs.docker.com/compose/django/ to get a basic dockerized django app going. I am able to run it locally without a problem but I am having trouble to deploy it to AWS using Elastic Beanstalk. After reading here, I figured that I need to translate docker-compose.yml into Dockerrun.aws.json for it to work.

我按照https://docs.docker.com/compose/django/上的说明获取基本的dockerized django应用程序。我能够在本地运行它没有问题,但我无法使用Elastic Beanstalk将其部署到AWS。在这里阅读之后,我想我需要将docker-compose.yml翻译成Dockerrun.aws.json才能工作。

The original docker-compose.yml is

最初的docker-compose.yml是

version: '2'
services:
  db:
    image: postgres
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

and here is what I translated so far

这是我到目前为止翻译的内容

{
  "AWSEBDockerrunVersion": 2,
  "volumes": [
    {
      "name": "db"
    },
    {
      "name": "web"
    }
  ],
  "containerDefinitions": [
    {
      "name": "db",
      "image": "postgres",
      "essential": true,
      "memory": 256,
      "mountPoints": [
        {
          "sourceVolume": "db"
          "containerPath": "/var/app/current/db"
        }
      ]
    },
    {
      "name": "web",
      "image": "web",
      "essential": true,
      "memory": 256,
      "mountPoints": [
        {
          "sourceVolume": "web"
          "containerPath": "/var/app/current/web"
        }
      ],
      "portMappings": [
       {
         "hostPort": 8000,
         "containerPort": 8000
       }
     ],
     "links": [
        "db"
      ],
      "command": "python manage.py runserver 0.0.0.0:8000"
    }
  ]
}

but it's not working. What am I doing wrong?

但它不起作用。我究竟做错了什么?

2 个解决方案

#1


8  

I was struggling to get the ins and outs of the Dockerrun format. Check out Container Transform: "Transforms docker-compose, ECS, and Marathon configurations"... it's a life-saver. Here is what it outputs for your example:

我正在努力获得Dockerrun格式的细节。查看容器转换:“转换docker-compose,ECS和Marathon配置”......它可以节省生命。以下是它为您的示例输出的内容:

{
    "containerDefinitions": [
        {
            "essential": true,
            "image": "postgres",
            "name": "db"
        },
        {
            "command": [
                "python",
                "manage.py",
                "runserver",
                "0.0.0.0:8000"
            ],
            "essential": true,
            "mountPoints": [
                {
                    "containerPath": "/code",
                    "sourceVolume": "_"
                }
            ],
            "name": "web",
            "portMappings": [
                {
                    "containerPort": 8000,
                    "hostPort": 8000
                }
            ]
        }
    ],
    "family": "",
    "volumes": [
        {
            "host": {
                "sourcePath": "."
            },
            "name": "_"
        }
    ]
}
Container web is missing required parameter "image".
Container web is missing required parameter "memory".
Container db is missing required parameter "memory".

That is, in this new format, you must tell it how much memory to allot each container. Also, you need to provide an image - there is no option to build. As is mentioned in the comments, you want to build and push to DockerHub or ECR, then give it that location: eg [org name]/[repo]:latest on Dockerhub, or the URL for ECR. But container-transform does the mountPoints and volumes for you - it's amazing.

也就是说,在这种新格式中,您必须告诉它分配每个容器的内存量。此外,您需要提供图像 - 没有选项可以构建。正如评论中提到的,你想构建并推送到DockerHub或ECR,然后给它那个位置:例如[org name] / [repo]:最新的Dockerhub,或者ECR的URL。但容器转换为你做mountPoints和卷 - 这太棒了。

#2


1  

You have a few issues.

你有一些问题。

1) 'web' doesn't appear to be an 'image', you define it as 'build . ' in your docker-compose.. Remember, the Dockerrun.aws.json will have to pull the image from somewhere (easiest is to use ECS's Repositories)

1)'web'似乎不是'图像',你将其定义为'build。 '在您的docker-compose中。记住,Dockerrun.aws.json必须从某处提取图像(最简单的是使用ECS的存储库)

2) I think 'command' is an array. So you'd have:

2)我认为'command'是一个数组。所以你有:

"command": ["python" "manage.py" "runserver" "0.0.0.0:8000"]

3) your mountPoints are correct, but the volume definition at the top is wrong. { "name": "web", "host": { "sourcePath": "/var/app/current/db" } Im not 100% certain, but the path works for me. if you have the Dockerrun.aws.json file, next to is a directory called /db .. then that will be the mount location.

3)你的mountPoints是正确的,但顶部的卷定义是错误的。 {“name”:“web”,“host”:{“sourcePath”:“/ var / app / current / db”}我不是100%肯定,但路径适合我。如果你有Dockerrun.aws.json文件,旁边是一个名为/ db ..的目录,那么这将是挂载位置。


分享到: