Amazon Elastic Beanstalk 中的错误 Docker 部署 - Docker 容器意外退出

Posted

技术标签:

【中文标题】Amazon Elastic Beanstalk 中的错误 Docker 部署 - Docker 容器意外退出【英文标题】:Error Docker deployment in Amazon Elastic Beanstalk - Docker container quit unexpectedly 【发布时间】:2016-07-10 01:47:16 【问题描述】:

我正在尝试通过 Elastic Beanstalk 部署一个简单的 Docker 容器,但出现 Docker 容器意外退出错误。不知道这里有什么问题。在此先感谢您的帮助。

Dockerrun.aws.json:


  "AWSEBDockerrunVersion": "1",
  "Image": 
    "Name": "janedoe/image",
    "Update": "true"
  ,
  "Ports": [
    "ContainerPort": "10010"
  ],
  "Volumes": [
    "HostDirectory": "/home/ec2-user/testdocker",
    "ContainerDirectory": "/home/ec2-user/testdocker"
  ],
  "Logging": "/home/ec2-user/testlogs"

Dockerfile:

FROM centos:centos6
MAINTAINER janedoe

运行回声“测试” 暴露10010

日志:

[2016-03-22T22:56:35.034Z] INFO  [15895] - [Application       update/AppDeployStage0/AppDeployPreHook/03build.sh] : Completed activity.     
Result:
  centos6: Pulling from library/centos
  Digest: sha256:ec1bf627545d77d05270b3bbd32a9acca713189c58bc118f21abd17ff2629e3f
  Status: Image is up to date for centos:centos6
  Successfully pulled centos:centos6
  Sending build context to Docker daemon 4.608 kB
  Sending build context to Docker daemon 4.608 kB

  Step 1 : FROM centos:centos6
   ---> ed452988fb6e
  Step 2 : MAINTAINER janedoe
   ---> Running in 8bce7dfb7e59
   ---> 04de6fffed04
  Removing intermediate container 8bce7dfb7e59
  Step 3 : RUN echo "test"
   ---> Running in 36cef1d7c0e5
  test
   ---> c5b3d119184c
  Removing intermediate container 36cef1d7c0e5
  Step 4 : EXPOSE 10010
   ---> Running in ea07cbcc1136
   ---> 45f9b3fe6503
  Removing intermediate container ea07cbcc1136
  Successfully built 45f9b3fe6503
  Successfully built aws_beanstalk/staging-app
[2016-03-22T22:56:35.034Z] INFO  [15895] - [Application update/AppDeployStage0/AppDeployPreHook] : Completed activity. Result:
  Successfully execute hooks in directory /opt/elasticbeanstalk/hooks/appdeploy/pre.
[2016-03-22T22:56:35.035Z] INFO  [15895] - [Application update/AppDeployStage0/EbExtensionPostBuild] : Starting activity...
[2016-03-22T22:56:35.550Z] INFO  [15895] - [Application update/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Starting activity...
[2016-03-22T22:56:35.550Z] INFO  [15895] - [Application update/AppDeployStage0/EbExtensionPostBuild/Infra-EmbeddedPostBuild] : Completed activity.
[2016-03-22T22:56:35.587Z] INFO  [15895] - [Application update/AppDeployStage0/EbExtensionPostBuild] : Completed activity.
[2016-03-22T22:56:35.588Z] INFO  [15895] - [Application update/AppDeployStage0/InfraCleanEbextension] : Starting activity...
[2016-03-22T22:56:36.107Z] INFO  [15895] - [Application update/AppDeployStage0/InfraCleanEbextension] : Completed activity. Result:
  Cleaned ebextensions subdirectories from .
[2016-03-22T22:56:36.107Z] INFO  [15895] - [Application update/AppDeployStage0] : Completed activity. Result:
  Application update - Command CMD-AppDeploy stage 0 completed
[2016-03-22T22:56:36.107Z] INFO  [15895] - [Application update/AppDeployStage1] : Starting activity...
[2016-03-22T22:56:36.108Z] INFO  [15895] - [Application update/AppDeployStage1/AppDeployEnactHook] : Starting activity...
[2016-03-22T22:56:36.108Z] INFO  [15895] - [Application update/AppDeployStage1/AppDeployEnactHook/00run.sh] : Starting activity...
[2016-03-22T22:56:44.157Z] INFO  [15895] - [Application update/AppDeployStage1/AppDeployEnactHook/00run.sh] : Activity execution failed, because: 268f1a5e43874771bc6039977e9eb048e704c0b94a5e100a2a9ffbf2d9d7f271
  Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Tue Mar 22 22:56:44 UTC 2016:. Check snapshot logs for details. (ElasticBeanstalk::ExternalInvocationError)
caused by: 268f1a5e43874771bc6039977e9eb048e704c0b94a5e100a2a9ffbf2d9d7f271
  Docker container quit unexpectedly after launch: Docker container quit unexpectedly on Tue Mar 22 22:56:44 UTC 2016:. Check snapshot logs for details. (Executor::NonZeroExitStatus)

【问题讨论】:

您是否检查过您的应用程序(在 S3 中由 AWS EB 管理的应用程序)的日志? 【参考方案1】:

您应该在 Dockerfile 上使用 CMD 而不是 RUN。

在 Dockerfile 中执行命令时,必须在 RUN、CMD 和 ENTRYPOINT(摘自Docker reference)之间谨慎选择:

运行:

RUN 指令将在新层之上执行任何命令 当前图像并提交结果。结果提交 镜像将用于 Dockerfile 中的下一步。

CMD:

CMD 的主要目的是 为执行提供默认值 容器。这些默认值可以包括可执行文件,也可以省略 可执行文件,在这种情况下,您必须指定一个 ENTRYPOINT 指导。

入口点:

ENTRYPOINT 允许您配置一个容器,该容器将作为 可执行文件。

您应该深入阅读Docker reference 和Docker best practices

除此之外,如果您打算使用在 Dockerrun.aws.json 中定义的卷,请记住 AWS documentation 中所述的内容:

使用时不要在 Dockerrun.aws.json 文件中指定 Image 键 一个 Dockerfile。 .Elastic Beanstalk 将始终构建和使用映像 存在时在 Dockerfile 中描述。

这意味着您的 Dockerrun.aws.json 将被忽略,所以要小心。

【讨论】:

【参考方案2】:

如果你像这样运行命令提示符输出会更容易看到

eb create <replace_with_your_env_name/> -vvv

【讨论】:

以上是关于Amazon Elastic Beanstalk 中的错误 Docker 部署 - Docker 容器意外退出的主要内容,如果未能解决你的问题,请参考以下文章

在 Amazon Elastic Beanstalk 上安装 Anaconda

Amazon Elastic Beanstalk 腻子

Amazon Elastic Beanstalk 如何采用自定义 python 命令?

如何卸载 Amazon Elastic Beanstalk 命令行界面?

Elastic Beanstalk 是不是支持 Amazon 的 Aurora DB?

使用 RabbitMQ 的 Amazon Elastic Beanstalk 上的芹菜超时异常