尽管遵循了大量的教程和指南,包括官方文档,但在尝试将我的docker容器部署到ECS时,我不断碰壁。
这就是我所做的:
ecs-cli configure --cluster my-cluster
ecs-cli up --keypair XXX --capability-iam --size 1 --instance-type t2.micro
ecs-cli compose --file docker-compose.staging.yml up
我的docker-compose.staging.yml
是
version: '2'
services:
web:
mem_limit: 128m
image: nginx:latest
ports:
- "80:80"
- "443:443"
volumes:
- src:/var/www
- vhost.staging.conf:/etc/nginx/conf.d/site.conf
- certificates:/etc/nginx/ssl
links:
- app
depends_on:
- app
app:
mem_limit: 128m
image: groberts12/php7.1-fpm-base
volumes:
- src:/var/www
运行compose命令后,我得到:
WARN[0000] Skipping unsupported YAML option... option name=networks
WARN[0000] Skipping unsupported YAML option for service... option name=networks service name=app
WARN[0000] Skipping unsupported YAML option for service... option name="depends_on" service name=web
WARN[0000] Skipping unsupported YAML option for service... option name=networks service name=web
INFO[0002] Using ECS task definition TaskDefinition="ecscompose-docker:5"
INFO[0002] Starting container... container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/app"
INFO[0002] Starting container... container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/web"
INFO[0002] Describe ECS container status container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/web" desiredStatus=RUNNING lastStatus=PENDING taskDefinition="ecscompose-docker:5"
INFO[0002] Describe ECS container status container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/app" desiredStatus=RUNNING lastStatus=PENDING taskDefinition="ecscompose-docker:5"
INFO[0014] Describe ECS container status container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/web" desiredStatus=RUNNING lastStatus=PENDING taskDefinition="ecscompose-docker:5"
INFO[0014] Describe ECS container status container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/app" desiredStatus=RUNNING lastStatus=PENDING taskDefinition="ecscompose-docker:5"
INFO[0026] Describe ECS container status container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/web" desiredStatus=RUNNING lastStatus=PENDING taskDefinition="ecscompose-docker:5"
INFO[0026] Describe ECS container status container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/app" desiredStatus=RUNNING lastStatus=PENDING taskDefinition="ecscompose-docker:5"
INFO[0032] Stopped container... container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/web" desiredStatus=STOPPED lastStatus=STOPPED taskDefinition="ecscompose-docker:5"
INFO[0032] Stopped container... container="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/app" desiredStatus=STOPPED lastStatus=STOPPED taskDefinition="ecscompose-docker:5"
ecs-cli ps
返回:
Name State Ports TaskDefinition
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/web STOPPED ExitCode: 1 xx.xxx.xxx.xxx:443->443/tcp, xx.xxx.xxx.xxx:80->80/tcp ecscompose-docker:5
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/app STOPPED ExitCode: 0 ecscompose-docker:5
以防万一,然后我开始运行服务:
ecs-cli compose --file docker-compose.staging.yml service up
这需要一段时间,但最后说完了:
WARN[0000] Skipping unsupported YAML option... option name=networks
WARN[0000] Skipping unsupported YAML option for service... option name=networks service name=app
WARN[0000] Skipping unsupported YAML option for service... option name="depends_on" service name=web
WARN[0000] Skipping unsupported YAML option for service... option name=networks service name=web
INFO[0001] Using ECS task definition TaskDefinition="ecscompose-docker:6"
INFO[0001] Created an ECS service service=ecscompose-service-docker taskDefinition="ecscompose-docker:6"
INFO[0002] Updated ECS service successfully desiredCount=1 serviceName=ecscompose-service-docker
INFO[0002] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0032] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0062] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0092] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0122] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0152] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0182] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0212] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0243] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0273] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0303] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0333] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0363] Describe ECS Service status desiredCount=1 runningCount=0 serviceName=ecscompose-service-docker
INFO[0378] ECS Service has reached a stable state desiredCount=1 runningCount=1 serviceName=ecscompose-service-docker
但是当再次检查进程列表时,它上面填充了重复的尝试。
在最终连接到容器实例后,我能够查询ecs-agent日志,但这并不包含太多信息,除了:
2017-03-29T15:24:11Z [WARN] Warning, link with no linkalias module="api client" linkName="app" task="ecscompose-docker:6 arn:aws:ecs:eu-west-1:571010915057:task/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, Status: (NONE->RUNNING) Containers: [web (PULLED->RUNNING),app (RUNNING->RUNNING),]" container="web(nginx:latest) (PULLED->RUNNING)"
在Docker上一切都运行得很好,没有任何问题,但对于devops游戏的这一部分是新的,所以完全混淆了可能是什么问题。
有什么建议吗?
答案 0 :(得分:0)
我会使用terraform构建您的Amazon ECS群集并使用任务和服务来部署docker容器。如果您想使用更多的docker兼容API解决方案,请使用docker swarm。 Docker compose更像是一个本地测试工具,而不是生产环境的协调器。
答案 1 :(得分:0)
最终,我不得不使用Elastic Beanstalk Multi-Container环境,该环境运行良好。
{
"AWSEBDockerrunVersion": 2,
"volumes": [{
"name": "php-app",
"host": {
"sourcePath": "/var/app/current/src"
}
}, {
"name": "nginx-proxy-conf",
"host": {
"sourcePath": "/var/app/current/vhost.staging.conf"
}
}, {
"name": "nginx-ssl-certificates",
"host": {
"sourcePath": "/var/app/current/certificates"
}
}],
"containerDefinitions": [
{
"name": "app",
"image": "groberts12/php7.1-fpm-base",
"environment": [{
"name": "Container",
"value": "groberts12/php7.1-fpm-base"
}],
"essential": true,
"memory": 128,
"mountPoints": [{
"sourceVolume": "php-app",
"containerPath": "/var/www"
}]
},
{
"name": "web",
"image": "nginx:latest",
"essential": true,
"memory": 128,
"portMappings": [{
"hostPort": 80,
"containerPort": 80
}, {
"hostPort": 443,
"containerPort": 443
}],
"links": [
"app"
],
"mountPoints": [{
"sourceVolume": "php-app",
"containerPath": "/var/www"
}, {
"sourceVolume": "nginx-proxy-conf",
"containerPath": "/etc/nginx/conf.d/default.conf"
}, {
"sourceVolume": "nginx-ssl-certificates",
"containerPath": "/etc/nginx/ssl"
}
]
}
]
}
希望这可以帮助任何有类似问题的人!