我使用AWS CodePipeline在Elastic Beanstalk上部署了一个多容器docker应用程序。该应用程序要求从EFS附加一个文件系统作为已装入的卷。为了连接并访问卷,我似乎需要重新启动docker。这在这个问题中有解释:将AWS EFS与Docker一起使用。虽然我可以根据这些指示成功连接文件系统,但我的部署有时会"失败",并出现以下错误:
Action execution failed Deployment completed, but with errors: ECS task stopped due to: Task failed to start. Failed to start ECS task: arn:aws… is STOPPED.
在这些情况下,应用程序成功部署,并且功能齐全,但我收到了一条失败消息,因为docker在检查期间尚未重新启动。
当这种情况发生时,我在Beanstalk日志中看到以下内容:
-------------------------------------
/var/log/ecs/ecs-init.log
-------------------------------------
2020-04-27T15:06:41Z [INFO] pre-start
2020-04-27T15:06:44Z [INFO] start
2020-04-27T15:06:44Z [INFO] No existing agent container to remove.
2020-04-27T15:06:44Z [INFO] Starting Amazon Elastic Container Service Agent
2020-04-27T15:07:20Z [INFO] Agent exited with code 0
2020-04-27T15:07:20Z [INFO] Error connecting to docker, backing off for 1.14777941s, error: Get http://unix.sock/v1.25/version: dial unix /var/run/docker.sock: connect: no such file or directory
2020-04-27T15:07:21Z [INFO] Error connecting to docker, backing off for 2.282153551s, error: Get http://unix.sock/v1.25/version: dial unix /var/run/docker.sock: connect: no such file or directory
2020-04-27T15:07:23Z [INFO] post-stop
2020-04-27T15:07:23Z [INFO] Cleaning up the credentials endpoint setup for Amazon Elastic Container Service Agent
2020-04-27T15:07:23Z [INFO] pre-start
2020-04-27T15:07:23Z [INFO] start
2020-04-27T15:07:23Z [INFO] Container name: /ecs-agent
2020-04-27T15:07:23Z [INFO] Removing existing agent container ID:
2020-04-27T15:07:23Z [INFO] Starting Amazon Elastic Container Service Agent
有没有办法防止这些错误的失败?
问题似乎是在ecs代理启动时docker守护进程没有运行。Elasticbeanstall有自己的方式来管理docker守护进程和ecs代理启动,除非手动/自动干预。
您能否确认是否通过任何EB扩展重新启动docker/ecs代理,因为这可能会阻碍EB的正常引导过程?
如果您正在使用EB扩展来启动/重新启动docker,请在"后部署"阶段使用不会影响引导进程的"钩子"来完成。以下是您可以使用的常见挂钩[1]。在这个链接[2]中也给出了一些例子。
参考文献:
[1]https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html
[2]https://github.com/equivalent/scrapbook2/blob/master/archive/blogs/2016-08-22-aws-elasticbeanstalk-hooks.md