我正在尝试使用弹性beantalk部署一个简单的节点和mysql服务器/数据库。我已成功将应用程序容器化,因此我知道docker-compose.yml文件正在运行。现在,我正在尝试将该文件转换为Dockerrun.aws.json文件,并使用弹性beantalk进行部署。每当我使用eb create
时,都会遇到相同的错误,即:
ERROR No ecs task definition (or empty definition file) found in environment
因此,首先我尝试手动编写此dockerrun.aws.json文件,但无济于事。然后我发现了容器转换包,该包应该将这些文件转换为不同格式。我有一个同事为我运行它,因为某些软件包在Mac而不是3上引用了python2.7 default时遇到问题,无论如何,然后我使用了container-transform给我的这个文件并修改了一些值以匹配其他示例我见过的dockerrun.aws.json文件,例如内存分配和正确的图像。
这是我的dockerrun.aws.json文件:
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"environment": [
{
"name": "NODE_ENV",
"value": "${NODE_ENV}"
},
{
"name": "MYSQL_URI",
"value": "${mysqlcontainer}"
}
],
"essential": true,
"image": "node:latest",
"links": [
"mysqlcontainer"
],
"memory": 512,
"name": "fec-api",
"mountPoints": [
{
"containerPath": "/var/lib/mysql",
"sourceVolume": "My-Db"
}
],
"portMappings": [
{
"containerPort": 3000,
"hostPort": 3000
}
]
},
{
"environment": [
{
"name": "MYSQL_DATABASE",
"value": "fec2"
},
{
"name": "MYSQL_USER",
"value": "fec"
},
{
"name": "MYSQL_PASSWORD",
"value": "fecpassword"
},
{
"name": "MYSQL_ROOT_PASSWORD",
"value": "rootpassword"
}
],
"essential": true,
"image": "mysql:5.7",
"memory": 512,
"mountPoints": [
{
"containerPath": "/var/lib/mysql",
"sourceVolume": "My-Db"
}
],
"name": "mysqlcontainer",
"portMappings": [
{
"containerPort": 3306,
"hostPort": 4306
}
]
}
],
"family": "",
"volumes": [
{
"host": {
"sourcePath": "my-db"
},
"name": "My-Db"
}
]
}
这是我的docker-compose.yml文件,可在本地运行:
version: '3'
services:
mysqlcontainer:
container_name: mysqlcontainer
build: ./db/
# image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: 'fec2'
MYSQL_USER: 'fec'
MYSQL_PASSWORD: 'fecpassword'
MYSQL_ROOT_PASSWORD: 'rootpassword'
ports:
- '4306:3306'
# expose:
# - '3306'
# Where our data will be persisted
volumes:
- my-db:/var/lib/mysql
# - /usr/src/init:/docker-entrypoint-initdb.d/
fec-api:
container_name: fec-api
build: ./server/
ports:
- '3000:3000' # expose ports - HOST:CONTAINER
environment:
- NODE_ENV=${NODE_ENV}
- MYSQL_URI=${mysqlcontainer}
depends_on:
- "mysqlcontainer"
links:
- "mysqlcontainer"
volumes:
my-db:
我希望在运行eb init
和eb create
之后在Elastic beantalk仪表板上获得绿色的选中标记。当我运行eb init
时,它确实识别出我具有docker配置,因此它必须知道我在根目录中具有dockerrun.aws.json文件,但是当我eb create
时出现错误。知道如何诊断此问题,或如何为dockerrun.aws.json文件正确构成docker-compose.yml吗?