Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 918
Janka Avatar asked May 06 '19 16:05

Janka


People also ask

How do I debug a docker compose file?

If you want to debug in Docker Compose, run the command Docker Compose Up using one of the two Docker Compose files as described in the previous section, and then attach using the appropriate Attach launch configuration. Launching directly using the normal launch configuration does not use Docker Compose.


1 Answers

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.

like image 78
Yann Avatar answered Oct 19 '22 05:10

Yann