How to disable output on one of containers?
Asked Answered
S

4

34

I am using Codeship CI for my project. I have selenium tests and I am using remote browser from selenium/standalone-firefox but it's producing tons of logs, so I want to disable stdout for selenium/standalone-firefox container.

Any ideas how I can do this?

Shirtmaker answered 12/10, 2016 at 10:50 Comment(3)
Depending on the docker-compose version, can you use "log_driver: none", or "logging: \ driver: none" ? docs.docker.com/compose/compose-file/#/loggingGuffey
Even using log_driver:none I get same output on stdoutShirtmaker
Hello, did you resolve your issue?Elsworth
S
2

I used this approach:

JAVA_OPTS=-Dselenium.LOGGER.level=WARNING

Added it as ENV variables in docker image for selenium/standalone-chrome.

Shirtmaker answered 22/8, 2017 at 13:47 Comment(1)
The only approach that works is to quiet the logs in the containerized application, like in the example above.Septimal
E
49

Use --log-driver=none in docker run:

docker run -d --log-driver=none selenium/standalone-firefox

Or docker-compose.yml

version: '2'
services:
  selenium:
    ports:
      - "4444:4444"
    logging:
      driver: "none"

    image:
      selenium/standalone-firefox

You can also send the log to a file using:

docker run -d --log-driver=none -e SE_OPTS="log log.txt" selenium/standalone-firefox

Or docker-compose.yml

version: '2'
services:
  selenium:
    ports:
      - "4444:4444"
    logging:
      driver: "none"
    environment:
      - SE_OPTS="log log.txt"

    image:
      selenium/standalone-firefox

For docker-compose file version 1 there is no other way than modifying the entry_point.sh

put this file next your docker-compose.yml entry_point.sh

#!/bin/bash

source /opt/bin/functions.sh

export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"

function shutdown {
  kill -s SIGTERM $NODE_PID
  wait $NODE_PID
}

if [ ! -z "$SE_OPTS" ]; then
  echo "appending selenium options: ${SE_OPTS}"
fi

SERVERNUM=$(get_server_num)
xvfb-run -n $SERVERNUM --server-args="-screen 0 $GEOMETRY -ac +extension RANDR" \
  java ${JAVA_OPTS} -jar /opt/selenium/selenium-server-standalone.jar \
  ${SE_OPTS} >/dev/null &
NODE_PID=$!

trap shutdown SIGTERM SIGINT
wait $NODE_PID

The use this docker-compose.yml:

selenium:
  ports:
    - "4444:4444"

  volumes:
    - .:/mnt
  image:
    selenium/standalone-firefox
  command: bash /mnt/entry_point.sh >/dev/null

Regards

Elsworth answered 12/10, 2016 at 12:27 Comment(8)
Sorry, but didn't help :(Shirtmaker
Just check if you are using the latest docker-compose version and also check if your docker-compose.yml begins with version: '2'Elsworth
I cannot usre version: '2' because of codeship, already tried with log_driver in v1Shirtmaker
Well forget about docker-compose and do it by hand with docker runElsworth
I cannot, because I prepare only yaml file that is run after pushing to branch, all I can modify is this pseudo docker-composeShirtmaker
I modified my answer to include the solution for version 1 docker-composeElsworth
Unforunately it's not working, used this like this: selenium_firefox: image: selenium/standalone-firefox ports: - 4444:4444 environment: - SE_OPTS= >/dev/null command: bash /opt/bin/entry_point.sh >/dev/null 2>&1Shirtmaker
You skipped the volumes part. Check the docker-compose.yml is at the bottom of the answer. Entry_point.sh needs to be changed because it executes java with an & at the end. So stdout redirection in command is uselessElsworth
P
3

CodeShip uses a custom variant of docker-compose v1 that accepts an environment setting. The following in codeship-services.yml worked for me:

selenium:
  image: selenium/standalone-chrome
  cached: true
  container_name: selenium
  environment:
    -  SE_OPTS=-log /tmp/log.txt

The SE_OPTS value should not be in quotes. /tmp is writeable, other locations may result in a permission error.

Poultryman answered 5/12, 2016 at 1:22 Comment(0)
S
2

I used this approach:

JAVA_OPTS=-Dselenium.LOGGER.level=WARNING

Added it as ENV variables in docker image for selenium/standalone-chrome.

Shirtmaker answered 22/8, 2017 at 13:47 Comment(1)
The only approach that works is to quiet the logs in the containerized application, like in the example above.Septimal
T
0

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.

In your case you can achieve what you wan by the following docker-compose.yml:

services:
  selenium:
    ports:
      - "4444:4444"
    attach: false

    image:
      selenium/standalone-firefox

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).

Alternative way With Docker Compose v2 you can see output for only selected service like this:

docker compose up --attach service_with_useful_output

Warning: Do not use this flag with Docker Compose v1 (docker-compose) for this purpose because docker-compose up --attach service_with_useful_output works differently.

Triadelphous answered 17/8, 2023 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.