'How to see error logs when docker-compose fails

I have a docker image that starts the entrypoint.sh script

This script checks if the project is well configured

If everything is correct, the container starts otherwise I received this error:

echo "Danger! bla bla bla"
exit 1000

Now if i start the container in this mode:

docker-compose up

i see the error correctly:

Danger! bla bla bla

but i need to launch the container in daemon mode:

docker-compose up -d

How can I show the log only in case of error?



Solution 1:[1]

The -d flag in docker-compose up -d stands for detached mode and not deamon mode.

In detached mode, your service(s) (e.g. container(s)) runs in the background of your terminal. You can't see logs in this mode.

To see all service(s) logs you need to run this command :

docker-compose logs -f

The -f flag stands for "Follow log output". This will output all the logs for each running service you have in your docker-compose.yml

From my understanding you want to fire up your service(s) with :

docker-compose up -d

In order to let service(s) run in the background and have a clean console output.

And you want to print out only the errors from the logs, to do so add a pipe operator and search for error with the grep command :

docker-compose logs | grep error

This will output all the errors logged by a docker service(s).

You'll find the official documentation related to the docker-compose up command here and to the logs command here. More info on logs-handling in this article. Related answer here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yann