在 Docker-Compose 中禁用一个容器的日志记录 [英] Disable logging for one container in Docker-Compose

查看:84
本文介绍了在 Docker-Compose 中禁用一个容器的日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Docker compose 启动的 Web 应用程序,我想禁用所有日志记录(或至少将其打印到系统日志而不是文件).

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

当我的 Web 应用程序运行时,它可以在启动时快速生成一个 11GB 的日志文件,因此这会非常快地占用我的磁盘空间.

When my web application works it can quickly generate an 11GB log file on startup so this eats up my disk space very fast.

我知道普通的 docker 有日志选项 作为它的运行命令,但在 Docker Compose 中我使用

I'm aware that normal docker has logging options for its run command but in Docker Compose I use

docker-compose up

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.

推荐答案

你应该能够使用 日志记录 功能.尝试将驱动程序设置为 none

You should be able to use logging feature. Try to set driver to none

logging:
    driver: none

完整示例:

services:
  website:
    image: nginx
    logging:
      driver: none

在 docker-compose 的最新版本中,如果所有服务都禁用了日志记录,则 docker-compose 将在分离模式下运行.要强制附加模式,您可以添加一个简单的静默服务,如下所示:

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

这篇关于在 Docker-Compose 中禁用一个容器的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆