Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing docker container log in aws ECS cluster

I have trouble showing log from my docker container in ecs.

What I did:
1) ssh into an ec2 instance of the cluster.
2) docker logs my service

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.

like image 813
superphung Avatar asked Sep 15 '25 10:09

superphung


2 Answers

open docker daemon file in /etc/docker/daemon.json and add log driver:

  {
     "log-driver": "awslogs"
  }

and restart docker with sudo systemctl restart docker

like image 103
amir Avatar answered Sep 17 '25 01:09

amir


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. you will get the container id from the docker ps command.

But if you want to push docker logs to cloudwatch logs then you have to choose aws-logs as docker log driver.

For some containers, it might work fine because those have docker log driver as json-file set in their task definition.

How to create a task definition? Reference: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/create-task-definition.html

Do let me know if you are still facing the issue.

like image 28
mohit Avatar answered Sep 17 '25 01:09

mohit