简体   繁体   English

在AWS ECS集群中显示Docker容器日志

[英]Showing docker container log in aws ECS cluster

I have trouble showing log from my docker container in ecs. 我无法在ecs中显示来自我的docker容器的日志。

What I did: 我做了什么:
1) ssh into an ec2 instance of the cluster. 1)ssh进入集群的ec2实例。
2) docker logs my service 2)码头工人记录我的服务

Then this message is showing up: 然后显示此消息:

FATA[0000] Error executing 'logs': Failed to get log configuration: Container 'my-container': Must specify log driver as awslogs 

What I am trying to do is to show log in the console. 我想做的是在控制台中显示日志。
What I don't understand is that for some container, the command docker logs works fine. 我不明白的是,对于某些容器,docker日志命令可以正常工作。

open docker daemon file in /etc/docker/daemon.json and add log driver: /etc/docker/daemon.json打开/etc/docker/daemon.json daemon文件并添加日志驱动程序:

  {
     "log-driver": "awslogs"
  }

and restart docker with sudo systemctl restart docker 并使用sudo systemctl restart docker

You should choose the docker log driver to json-log while creating the task definition revision in ECS, If you want to see the docker logs with docker logs container-id command. 在ECS中创建任务定义修订版时,应选择docker log driver为json-log ,如果要使用docker logs container-id命令查看Docker日志。 you will get the container id from the docker ps command. 您将从docker ps命令获取容器ID。

But if you want to push docker logs to cloudwatch logs then you have to choose aws-logs as docker log driver. 但是,如果要将docker日志推送到cloudwatch日志,则必须选择aws-logs作为docker日志驱动程序。

For some containers, it might work fine because those have docker log driver as json-file set in their task definition. 对于某些容器,它可能工作正常,因为那些容器在其任务定义中将docker log driver作为json-file设置。

How to create a task definition? 如何创建任务定义? Reference: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-task-definition.html 参考: https : //docs.aws.amazon.com/AmazonECS/latest/developerguide/create-task-definition.html

Do let me know if you are still facing the issue. 如果您仍然遇到问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS ECS集群未显示容器 - AWS ECS cluster is not showing container 在单独的Docker容器(AWS ECS)中连接到MongoDB - Connect to MongoDB in separate docker container (AWS ECS) aws ecs docker 容器无法访问互联网 - aws ecs docker container cannot reach the internet AWS ECS 上的 Docker 纯数据容器 - Docker data-only container on AWS ECS AWS ECS docker 容器 RDS 集成 - AWS ECS docker container RDS integration AWS ECS - 如何从 ECS 容器登录到 cloudwatch? - AWS ECS - how to log to cloudwatch from ECS container? 如何使用 Pulumi 配置 AWS ECS Fargate 任务/集群以访问私有 Docker 容器注册表(如 GitHub 容器注册表)? - How to configure AWS ECS Fargate Tasks/Cluster to access private Docker Container Registry (like GitHub Container Registry) with Pulumi? 从 docker 容器(Spring Boot 应用程序)托管的 Amazon AWS ECS 集群以编程方式发送电子邮件的最佳方式? - Best way to send e-mail programmatically from docker container (Spring Boot app) hosted Amazon AWS ECS Cluster? AWS EC2 ECS 在您的集群中未找到任何容器实例 - AWS EC2 ECS No Container Instances were found in your cluster Docker 容器在使用 AWS ECR 的 AWS ECS 中不起作用 - Docker Container not working in AWS ECS using AWS ECR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM