如何为 Django 将 docker-compose.yml 转换为 Dockerrun.aws.json [英] How to translate docker-compose.yml to Dockerrun.aws.json for Django
问题描述
我正在按照 https://docs.docker.com/compose/django/ 以获得基本的 dockerized django 应用程序.我可以毫无问题地在本地运行它,但是我无法使用 Elastic Beanstalk 将它部署到 AWS.阅读此处后,我想我需要翻译docker-compose.yml 到 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.
原来的docker-compose.yml是
The original docker-compose.yml is
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
这是我目前翻译的内容
{
"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?
推荐答案
我一直在努力了解 Dockerrun
格式的来龙去脉.查看 容器转换:转换 docker-compose、ECS 和 Marathon 配置"...它是救命稻草.这是它为您的示例输出的内容:
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:
{
"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".
也就是说,在这种新格式中,您必须告诉它为每个容器分配多少内存.此外,您需要提供图像 - 没有构建选项.正如评论中提到的,你想构建并推送到 DockerHub 或 ECR,然后给它那个位置:例如 [org name]/[repo]:latest
on Dockerhub,或 ECR 的 URL.但是 container-transform
为您做了 mountPoints
和 volumes
- 这太棒了.
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.
这篇关于如何为 Django 将 docker-compose.yml 转换为 Dockerrun.aws.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!