Django AWS弹性豆茎给出;无法翻译主机名“;db";解决;错误
我一直在尝试部署由Django、Postgresql和Nginx组成的docker。当我这样做的时候,它工作得很好 sudo docker-compose up Dockerfile dockrun.aws.json docker-compose.yml 我意识到的一件事是,当我在我的机器上使用docker compose时,我会运行3个不同的容器。但是在EB上,我只看到一个容器在运行 我想这是因为我从docker hub获取了我用这些文件构建的图像,不知何故导致了这3个容器成为一个,并且它搞乱了主机名的识别?我还是不太确定。非常感谢您的帮助。谢谢Django AWS弹性豆茎给出;无法翻译主机名“;db";解决;错误,django,amazon-web-services,docker,docker-compose,amazon-elastic-beanstalk,Django,Amazon Web Services,Docker,Docker Compose,Amazon Elastic Beanstalk,我一直在尝试部署由Django、Postgresql和Nginx组成的docker。当我这样做的时候,它工作得很好 sudo docker-compose up Dockerfile dockrun.aws.json docker-compose.yml 我意识到的一件事是,当我在我的机器上使用docker compose时,我会运行3个不同的容器。但是在EB上,我只看到一个容器在运行 我想这是因为我从docker hub获取了我用这些文件构建的图像,不知何故导致了这3个容器成为一个,并且它搞乱
dockrun.aws.json
应与docker compose.yml
主机名“db”无法转换为地址的原因是docker compose.yml
和dockrun.aws.json
文件描述了不同的体系结构:
docker compose.yml中有3个容器
dockrun.aws.json中只有1个容器
db
主机名,但找不到它,因为db
未在dockrun.aws.json
修复dockrun.aws.json
因此,请更新您的dockrun.aws.json
。您可以手动或使用方便的工具:
a) 手动更新
您可以使用示例,例如:
- **
$container transform docker-compose.yml>dockrun.aws.json
dockrun.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"
}
]
}
{
"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"
}
]
}
注意::当然,您应该修复缺少的设置,例如db
和nginx
容器的memory
您可以完全忽略网络
根据:
例如,假设您的应用程序位于名为myapp
的目录中,并且您的docker compose.yml
如下所示:
docker compose.yml
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
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
运行docker compose up
时,会发生以下情况:
myapp\u default
的网络web
的配置创建的。它以web
的名称加入网络myapp\u default
db
的配置创建的。它以db
的名称加入网络myapp\u default
网络
,因此可以忽略它
docker compose.yml
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
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
和$container transform docker-compose.yml>dockrun.aws.json
将生成:
dockrun.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"
}
]
}
{
"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"
}
]
}
您在这两种情况下使用的是同一个docker compose文件吗?非常感谢您的帮助!但是现在我面临着由于以下原因而停止ECS任务的
错误:任务启动失败。(nginx:CannotCreateContainerError:daemon的错误响应:create./config/nginx:“./config/nginx”包含本地卷名的无效字符,仅“[a-zA-Z0-9]允许使用[a-zA-Z0-9.-]。如果您打算传递主机目录,请使用aws端的绝对路径db:web:)
。这是nginx.conf问题吗?再次感谢您!!@Jason,像往常一样,nginx config存储在类似/etc/nginx/conf
的地方。对于您的情况,请尝试绝对路径而不是/config/nginx
version: "3"
services:
web:
build: .
ports:
- "8000:8000"
db:
image: postgres
ports:
- "8001:5432"
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
{
"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"
}
]
}