Disable logging for one container in Docker-Compose

DockerDocker Compose

Docker Problem Overview


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.

Docker Solutions


Solution 1 - Docker

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

Solution 2 - Docker

For a quick config example, something like

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

Solution 3 - Docker

Not exactly what is asked, but as of September 2021, the --attach parameter allows to select the services to listen to.

For example docker compose up --attach your-service will only display logs for your-service.

Solution 4 - Docker

As the second option, you may be interested in not fully removing logging (what 'none' value does), but in storing logs of some services in syslog, there is the driver for it, for instance:

certbot:
  image: certbot/certbot
  restart: unless-stopped
  logging:
    driver: "syslog"

Note that the syslog daemon must be running on the host machine. To see the logs use for example: journalctl -n 100 --no-pager

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGreenGodotView Question on Stackoverflow
Solution 1 - DockerFuxiView Answer on Stackoverflow
Solution 2 - DockerslatunjeView Answer on Stackoverflow
Solution 3 - DockerKiprView Answer on Stackoverflow
Solution 4 - DockerfunnydmanView Answer on Stackoverflow