Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running docker compose up outputs logs even when logging driver is set to none

I'm using docker-compose to run tests for my app. My docker-compose.yml file has three services, one for mongodb, one for my app, and a third for my tests. I have logging: driver: "none" set for the app and mongodb because I only want to see the test logs.

This previously worked as expected. Since the last time I worked on this project, I've upgraded docker desktop on my mac to Version 3.5.2 (3.5.2.18). Now, all container logs flood my terminal when running. I'm not sure what has changed.

version: '3.1'

services:

  mongodb:
    image: mongo
    expose:
      - 27017
    logging:
      driver: "none"

  rsscloud:
    build: .
    command: node --use_strict app.js
    environment:
      DOMAIN: rsscloud
      PORT: 5337
      MONGODB_URI: mongodb://mongodb:27017/rsscloud
      NODE_TLS_REJECT_UNAUTHORIZED: 0
    expose:
      - 5337
    depends_on:
      - mongodb
    logging:
      driver: "none"

  rsscloud-tests:
    build: .
    command: dockerize -wait tcp://mongodb:27017 -wait http://rsscloud:5337 -timeout 10s bash -c "npm test"
    environment:
      APP_URL: http://rsscloud:5337
      MONGODB_URI: mongodb://mongodb:27017/rsscloud
      MOCK_SERVER_DOMAIN: rsscloud-tests
      MOCK_SERVER_PORT: 8002
      SECURE_MOCK_SERVER_PORT: 8003
    volumes:
      - ./xunit:/app/xunit
    expose:
      - 8002
      - 8003
    depends_on:
      - mongodb
      - rsscloud

I run docker compose up --build --abort-on-container-exit

Here is a sample of the output:

Attaching to mongodb_1, rsscloud-tests_1, rsscloud_1
rsscloud-tests_1  | 2021/07/27 15:43:58 Waiting for: tcp://mongodb:27017
rsscloud-tests_1  | 2021/07/27 15:43:58 Waiting for: http://rsscloud:5337
rsscloud-tests_1  | 2021/07/27 15:43:58 Connected to tcp://mongodb:27017
mongodb_1         | {"t":{"$date":"2021-07-27T15:43:58.964+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.18.0.4:39890","uuid":"d9874a7d-e9c3-4e88-b163-c9b9deb582d1","connectionId":2,"connectionCount":2}}
rsscloud-tests_1  | 2021/07/27 15:43:58 Received 200 from http://rsscloud:5337
rsscloud_1        | [15:43:58.993] GET / 200 577 - ::ffff:172.18.0.4 - 20.885 ms
rsscloud-tests_1  | 
rsscloud-tests_1  | > [email protected] test /app
rsscloud-tests_1  | > mocha -R mocha-multi --reporter-options spec=-,xunit=xunit/test-results.xml --timeout 10000
rsscloud-tests_1  | 
rsscloud-tests_1  | 
rsscloud-tests_1  | 
rsscloud-tests_1  |   Ping XML-RPC to http-post returning XML
mongodb_1         | {"t":{"$date":"2021-07-27T15:44:00.100+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.18.0.4:39892","uuid":"df65fb3a-9913-4075-9671-34d2e9a4d7e8","connectionId":3,"connectionCount":3}}
mongodb_1         | {"t":{"$date":"2021-07-27T15:44:00.105+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn3","msg":"client metadata","attr":{"remote":"172.18.0.4:39892","client":"conn3","doc":{"driver":{"name":"nodejs","version":"4.0.1"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"5.10.25-linuxkit"},"platform":"Node.js v12.22.3, LE (unified)|Node.js v12.22.3, LE (unified)"}}}
rsscloud-tests_1  |     → MongoDB 'rsscloud' Database Connected
rsscloud-tests_1  |     → Mock server started on port: 8002
rsscloud-tests_1  |     → Mock secure server started on port: 8003
like image 850
Andrew Shell Avatar asked Jan 25 '23 07:01

Andrew Shell


2 Answers

This is an intentional change with docker compose. You can change it back to using docker-compose which is different from docker compose and will likely provide your expected previous behavior.

Or you can run docker compose up -d and docker compose logs rsscloud-tests but I'm not sure there's an easy way to do that with --abort-on-container-exit since that's likely incompatible with the -d option.

I'd recommend following this enhancement request and give it your thumbs up: https://github.com/docker/compose-cli/issues/1615

like image 112
BMitch Avatar answered May 06 '23 13:05

BMitch


As a complement of the given answer:

I'd recommend following this enhancement request and give it your thumbs up: https://github.com/docker/compose-cli/issues/1615

Now we're able to use:
docker compose up --attach service_name

This will attach the output to the service_name, showing logs just from this service.

PS.: This command only works on docker compose V2 version which already have a good support for Docker on Windows, but when it comes to linux, the --attach argument isn't very well implemented so far. For linux, I would advise to keep using logging driver (setting it to none if you wish docker not to output logs), running docker-compose V1. You may find more information about docker compose V2 at the docs:

https://docs.docker.com/compose/cli-command/

like image 45
marcelfox Avatar answered May 06 '23 13:05

marcelfox