141

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.

7 Answers 7

261

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
15
  • 5
    The link to the docs is appreciated, but could you please explain exactly how that option should be used to make a container not write logs? I'm setting the driver to none but my postgres container still writes heaps of crap to stdout while my tests are running. Very annoying. Commented Feb 11, 2017 at 22:39
  • 1
    I update the link. Hopefully it should have all the info now
    – Fuxi
    Commented Feb 12, 2017 at 19:51
  • 4
    I found this solution and used it earlier this year. However the behaviour of docker-compose has now changed and driver: none no longer has this effect in the latest docker versions. See this PR against docker-compose for more details.
    – Phil Haigh
    Commented Aug 2, 2021 at 14:28
  • 8
    As of September 2021, this will only work if using the docker-compose commands (note the hyphen) and won't work if you are using the new compose commands integrated directly into Docker, i.e. docker compose up (note that the hyphen has been replaced with a space because it's now referencing a command in Docker as opposed to Docker Compose) Commented Sep 27, 2021 at 15:38
  • 5
    this doesn't seem to work at all anymore even with docker-compose. Anyone got insight? On mac m1
    – MikeSchem
    Commented Dec 20, 2021 at 18:32
36

For a quick config example, something like

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

19

Not exactly what is asked, but as of September 2021 (on Compose V2), 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.

2
  • 1
    This is very useful, but why is it not documented in docs.docker.com/compose/reference/up ?
    – Reorx
    Commented Apr 8, 2022 at 12:37
  • 4
    Pay attention that --attach will only run the specified container in the docker-compose v1. You should have compose v2 installed for this to work. Please check your compose version by running docker compose --version. Use other answer if you want to keep using v1. Commented May 21, 2022 at 4:54
6

If you cannot use Kipr's suggestion of --attach flag ( e.g. IntelliJ IDEA UX limitations ), you can achieve needed result by editing docker-compose.yml file .

Now with Docker Compose v2 you can remove the version top-level configuration. It enables Compose Specification as Docker Compose "version" (see "Warning" on the related doc page ). The Specification allows to use the "attach" configuration.

Example docker-compose.yml:

services:
  website:
    image: nginx
    attach: false

Warning: Note that there is no version key here. It is important. Also note that Docker Compose v2 command is docker compose (so please, do NOT use docker-compose command with this file).

5
  • I have not been able to use this option. Every time that I try to use I get a Additional property attach is not allowed. Could I get an indication of the Compose version you are running? I am running Client: Docker Engine - Community Version: 23.0.1 Docker Compose version v2.16.0 Commented Sep 21, 2023 at 15:08
  • by contrast, the --attach and also the --no-attach flags work just fine. Commented Sep 21, 2023 at 15:09
  • 1
    This should be the new selected answer
    – sayandcode
    Commented Sep 25, 2023 at 11:39
  • @largehadroncollider Most probably you have version: ... in the top of your docker-compose.yml. Please, remove that line and use docker compose command (without - (hyphen) between docker and compose)
    – Nick Vee
    Commented Sep 26, 2023 at 16:13
  • This worked for me, even with version: '3.8' Commented May 17 at 0:54
3

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

1

The way I solved this is to create an alias in ~/.bash-aliases (or ~/.zaliases on zsh):

alias up='(docker compose up -d && docker compose logs --since 2s -f) || (docker compose stop)'

By using the above up alias, now you can use the logger field in service description:

services:
    your_service:
        logging:
            driver: none 

The reason you see the logs despite driver: none in yaml and starting with docker compose, is because docker compose up attaches to the containers being ran, it does not rely on the logging API. But docker compose logs -f attaches to the logs, which are not stored when you use the none driver.

If you want to hide warnings about no logs for some services, the following alias could be used:

alias up='docker compose up -d && (docker compose logs --since 3s -f 2> >(grep -v "Error response from daemon: configured logging driver does not support reading"))) || (docker compose stop)'
-2

Never disable logging, instead you can set some limitation on your services:

version: '3'
services:
  app1: 
    image: kong 
    logging: 
          options: 
               max-size: "10m" 
               max-file: "3"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.