[英]Unable to see container logs from my C++ App when using client.containers.run of docker-py
在带有 docker-py 的 python 中,我正在运行两个 docker 容器:
我使用以下 docker-py API:
container = client.containers.run(imageName, detach=True, name=containerName, ports = ports, volumes = volumes)
1606303570: mosquitto version 1.6.12 starting
1606303570: Config loaded from /mosquitto/config/mosquitto.conf.
1606303570: Opening ipv4 listen socket on port 1883.
1606303570: Opening ipv6 listen socket on port 1883.
1606303570: mosquitto version 1.6.12 running
这似乎有点类似于这个问题https://github.com/docker/docker-py/issues/2697
经过几次测试,这是我的发现:
与eclipse-mosquitto相同的测试总是给我一个充满日志的 Docker 桌面仪表板。
有人知道如何使用client.containers.run从我的自定义容器中获取我的日志吗?
经过几天的研究,我能够提供额外的信息来隔离这个问题。
C++ testApp 代码示例:
#include <iostream>
#include <unistd.h>
int main(int argc, char **argv)
{
printf("\nServer is starting... !!\n\n");
while (1)
usleep(100000);
return 1;
}
DockerFile 内容:
FROM amd64/ubuntu:latest
ADD / test
WORKDIR /test
RUN chmod +x testApp
ENTRYPOINT ["/test/testApp"]
Python代码
import docker, time
imageName = 'test'
imagePath = 'C:/test/image'
dockerClient = docker.from_env()
try:
dockerClient.images.remove(image = imageName, force = True)
except (docker.errors.ImageNotFound):
pass
dockerClient.images.build(path = imagePath, tag = imageName, rm=True)
container = dockerClient.containers.run(imageName, detach=True, name=imageName)
while True:
print(container.logs())
time.sleep(1)
总而言之,当从命令行docker run -it test
运行我的自定义容器时,我得到了日志,但是当使用 docker -py和dockerClient.containers.run
运行它时,我的日志保持为空。
有人知道如何使用dockerClient.containers.run
从我的自定义容器中获取我的日志吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.