在 Amazon ECS 中配置 Docker 进程守护程序的详细输出 - Amazon Elastic Container Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

在 Amazon ECS 中配置 Docker 进程守护程序的详细输出

如果您遇到与 Docker 容器或映像有关的问题,可以在 Docker 进程守护程序上打开调试模式。使用调试可以从进程守护程序中提供更详细的输出,您可以使用它来检索从容器注册表(例如 Amazon ECR)中发送的错误消息。

重要

此过程是经 Amazon ECS 优化的 Amazon Linux AMI 编写的。对于其他操作系统,请参阅 Docker 文档中的启用调试和使用 systemd 控制和配置 Docker

要在经 Amazon ECS 优化的 Amazon Linux AMI 上使用 Docker 进程守护程序调试模式
  1. 连接到您的容器实例。

  2. 使用文本编辑器(例如 vi)打开 Docker 选项文件。对于经 Amazon ECS 优化的 Amazon Linux AMI,Docker 选项文件位于 /etc/sysconfig/docker

  3. 查找 Docker 选项语句并将 -D 选项添加到用引号引起的字符串。

    注意

    如果 Docker 选项语句以 # 开头,则您需要删除该字符,以取消语句的注释并启用选项。

    对于经 Amazon ECS 优化的 AMI,Docker 选项语句称作 OPTIONS。例如:

    # Additional startup options for the Docker daemon, for example: # OPTIONS="--ip-forward=true --iptables=true" # By default we limit the number of open files per container OPTIONS="-D --default-ulimit nofile=1024:4096"
  4. 保存文件并退出文本编辑器。

  5. 重新启动 Docker 进程守护程序。

    sudo service docker restart

    您可以在一个 (扩展) 代码行中执行所有这些操作:

    Stopping docker: [ OK ] Starting docker: . [ OK ]
  6. 重新启动 Amazon ECS 代理。

    sudo service ecs restart

现在,您的 Docker 日志应显示更详细的输出。

time="2015-12-30T21:48:21.907640838Z" level=debug msg="Unexpected response from server: \"{\\\"errors\\\":[{\\\"code\\\":\\\"DENIED\\\",\\\"message\\\":\\\"User: arn:aws:sts::1111:assumed-role/ecrReadOnly/i-abcdefg is not authorized to perform: ecr:InitiateLayerUpload on resource: arn:aws:ecr:us-east-1:1111:repository/nginx_test\\\"}]}\\n\" http.Header{\"Connection\":[]string{\"keep-alive\"}, \"Content-Type\":[]string{\"application/json; charset=utf-8\"}, \"Date\":[]string{\"Wed, 30 Dec 2015 21:48:21 GMT\"}, \"Docker-Distribution-Api-Version\":[]string{\"registry/2.0\"}, \"Content-Length\":[]string{\"235\"}}"