Docker Compose Up-删除日志输出中的服务名称
是否可以删除docker compose up的日志输出中的服务名称 我的日志当前如下所示:Docker Compose Up-删除日志输出中的服务名称,docker,logging,docker-compose,Docker,Logging,Docker Compose,是否可以删除docker compose up的日志输出中的服务名称 我的日志当前如下所示: serviceA | log1 serviceB | log2 serviceB | log3 serviceA | log4 log1 log2 log3 log4 version: "3.7" services: some-service: image: some-service logging: drive
serviceA | log1
serviceB | log2
serviceB | log3
serviceA | log4
log1
log2
log3
log4
version: "3.7"
services:
some-service:
image: some-service
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
但我想让它们看起来像这样:
serviceA | log1
serviceB | log2
serviceB | log3
serviceA | log4
log1
log2
log3
log4
version: "3.7"
services:
some-service:
image: some-service
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
您可以为以下服务配置日志记录的状态:
serviceA | log1
serviceB | log2
serviceB | log3
serviceA | log4
log1
log2
log3
log4
version: "3.7"
services:
some-service:
image: some-service
logging:
driver: "json-file"
options:
max-size: "200k"
max-file: "10"
但在运行docker compose up
时,我找不到任何选项从日志中删除服务名称
更新
根据的建议,我尝试了以下命令:
docker-compose up --no-color 2>&1 | sed 's/^[^ ]* | //'
使用以下docker compose文件:
version: "3"
services:
consumer:
image: debian:stretch-slim
command:
[
"bash",
"-c",
"while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done ",
]
ideas:
image: debian:stretch-slim
restart: always
command:
[
"bash",
"-c",
"while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done ",
]
输出如下所示
ideas_1 | Sun Oct 20 05:56:23 UTC 2019 99295bdcbf2c
ideas_1 | Sun Oct 20 05:56:25 UTC 2019 99295bdcbf2c
Sun Oct 20 05:56:25 UTC 2019 dd45c5900159
ideas_1 | Sun Oct 20 05:56:27 UTC 2019 99295bdcbf2c
ideas_1 | Sun Oct 20 05:56:27 UTC 2019 99295bdcbf2c
Sun Oct 20 05:56:27 UTC 2019 dd45c5900159
Sun Oct 20 05:56:29 UTC 2019 dd45c5900159
ideas_1 | Sun Oct 20 05:56:30 UTC 2019 99295bdcbf2c
因此,它适用于服务
消费者
,但不适用于创意
当前您无法删除前缀,我在源代码中没有看到选项
docker compose
是用python编写的,请随意修补
解决办法将:
docker-compose up --no-color 2>&1 | sed 's/^[^ ]* *| //'
或
我用这个非常小的docker compose.yaml
version: '3.7'
services:
serviceA:
image: debian:stretch-slim
command: ["bash","-c","while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done "]
serviceB:
image: debian:stretch-slim
restart: always
command: ["bash","-c","while ( true ) ; do echo $$(date) $$( hostname ) ; sleep $$(( $$RANDOM %4 )) ; done "]
看来你现在可以了,这个公关被合并了:
例如:
docker compose up--没有日志前缀
您没有使用docker compose up-d
?守护程序模式不显示日志。但是我想看看日志,刚开始时没有“服务名称”,我已经更新了我的问题。。。所以它基本上部分工作:)我犯了一个错误,您需要添加一个*
,因为空格的数量是可变的