Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable logging for one container in Docker-Compose

I have a web application launched using Docker compose that I want to disable all logging for (or at the very least print it out to syslog instead of a file).

When my web application works it can quickly generate an 11GB log file on startup so this eats up my disk space very fast.

I'm aware that normal docker has logging options for its run command but in Docker Compose I use

docker-compose up

in the application folder to start my application. How would I enable this functionality in my case? I'm not seeing a specific case anywhere online.

like image 778
GreenGodot Avatar asked Jan 04 '16 11:01

GreenGodot


People also ask

How do I restrict docker logs?

To set log limits for containers on a host --log-opt can be configured with max-size and max-file so that a containers logs are rolled over when they reach a max limit and only a certain number of files are saved before being discarded. Hope this helps!

How do I change the log level in a docker container?

You can run the command kubectl exec -it <container_name> bash and use the command line inside the container to change the environment variable . You can do it by running the command export LOG_LEVEL=debug or export LOG_LEVEL=error inside the container.

How do I monitor logs from a docker container?

Viewing Container Logs You can use docker ps -a to get the IDs and names of your containers. The logs command prints the container's entire log output to your terminal. The output will not be continuous. If you'd like to keep streaming new logs, add the --follow flag to the command.


2 Answers

You should be able to use logging feature. Try to set driver to none

logging:
    driver: none

Full example:

services:
  website:
    image: nginx
    logging:
      driver: none

In recent versions of docker-compose, if all of the services have disabled logging, docker-compose will act as in detach mode. To force the attached mode you can add a simple silent service like that:

services:
  website:
    image: nginx
    logging:
      driver: none

  force-attach:
    image: bash
    command: tail -f /dev/null
like image 200
Fuxi Avatar answered Oct 22 '22 22:10

Fuxi


For a quick config example, something like

version: '3'
services:
    postgres:
        image: postgres:9.6
        logging:
            driver: none 

like image 29
slatunje Avatar answered Oct 22 '22 22:10

slatunje