Dockerrun.aws.json
应该与docker-compose.yml
主机名“db”无法转换为地址的问题原因是docker-compose.yml
and Dockerrun.aws.json
文件描述了不同的架构:
- 里面有3个集装箱
docker-compose.yml
- 里面只有1个集装箱
Dockerrun.aws.json
因此,应用程序试图解决db
主机名并且找不到它,因为db
未声明于Dockerrun.aws.json
Fix Dockerrun.aws.json
所以,更新你的Dockerrun.aws.json
。您可以手动或使用方便的工具来完成micahhausler/容器变换:
a) 手动更新
您可以使用示例,例如:
-
k2works/aws-eb-docker-多容器-示例**
b) 或使用更新它micahhausler/container-transform
你可以试试micahhausler/容器变换:
转换 docker-compose、ECS 和 Marathon 配置
转换 docker-compose、ECS 和 Marathon 配置
以下是它针对您的情况输出的内容:
$ container-transform docker-compose.yml > Dockerrun.aws.json
Dockerrun.aws.json
{
"containerDefinitions": [
{
"essential": true,
"image": "postgres",
"name": "db"
},
{
"essential": true,
"image": "nginx",
"mountPoints": [
{
"containerPath": "/etc/nginx/conf.d",
"sourceVolume": "_ConfigNginx"
}
],
"name": "nginx",
"portMappings": [
{
"containerPort": 8000,
"hostPort": 8000
}
]
},
{
"essential": true,
"links": [
"db:db"
],
"mountPoints": [
{
"containerPath": "/code",
"sourceVolume": "_"
}
],
"name": "web"
}
],
"family": "",
"volumes": [
{
"host": {
"sourcePath": "."
},
"name": "_"
},
{
"host": {
"sourcePath": "./config/nginx"
},
"name": "_ConfigNginx"
}
]
}
Note::当然,您应该修复丢失的设置,例如memory
for db
and nginx
容器。
你可以省略networks
at all
根据Compose 中的网络 | Docker 文档:
例如,假设您的应用程序位于名为的目录中myapp
, 和你的docker-compose.yml
看起来像这样:
docker-compose.yml
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
当你跑步时docker-compose up
,会发生以下情况:
- 一个名为
myapp_default
被建造。
- 使用以下命令创建容器
web
的配置。它加入网络myapp_default
以...之名web
.
- 使用以下命令创建容器
db
的配置。它加入网络myapp_default
以...之名db
.
所以,由于所有容器都链接到同一个some_network
,可以省略。
docker-compose.yml
version: '3'
services:
db:
image: postgres
hostname: db
web:
restart: always
build: .
volumes:
- .:/code
hostname: web
expose:
- "8000"
depends_on:
- db
links:
- db:db
nginx:
image: nginx
hostname: nginx
ports:
- "8000:8000"
volumes:
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
And $ container-transform docker-compose.yml > Dockerrun.aws.json
将产生:
Dockerrun.aws.json
{
"containerDefinitions": [
{
"essential": true,
"image": "postgres",
"name": "db"
},
{
"essential": true,
"image": "nginx",
"mountPoints": [
{
"containerPath": "/etc/nginx/conf.d",
"sourceVolume": "_ConfigNginx"
}
],
"name": "nginx",
"portMappings": [
{
"containerPort": 8000,
"hostPort": 8000
}
]
},
{
"essential": true,
"links": [
"db:db"
],
"mountPoints": [
{
"containerPath": "/code",
"sourceVolume": "_"
}
],
"name": "web"
}
],
"family": "",
"volumes": [
{
"host": {
"sourcePath": "."
},
"name": "_"
},
{
"host": {
"sourcePath": "./config/nginx"
},
"name": "_ConfigNginx"
}
]
}