Docker-compose disable output on one of containers

流过昼夜 提交于 2020-05-11 03:51:39

问题


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?


回答1:


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




回答2:


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.




回答3:


I used this approach:

JAVA_OPTS=-Dselenium.LOGGER.level=WARNING

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



来源:https://stackoverflow.com/questions/39996732/docker-compose-disable-output-on-one-of-containers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!