[英]Unable to see container logs from my C++ App when using client.containers.run of docker-py
In python with docker-py, I am running two docker containers:在带有 docker-py 的 python 中,我正在运行两个 docker 容器:
I use the following docker-py API:我使用以下 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
This seems to be kind of similar to this issue https://github.com/docker/docker-py/issues/2697这似乎有点类似于这个问题https://github.com/docker/docker-py/issues/2697
After several tests this is my findings:经过几次测试,这是我的发现:
The same tests with eclipse-mosquitto gives me always a Docker Desktop Dashboard full of logs.与eclipse-mosquitto相同的测试总是给我一个充满日志的 Docker 桌面仪表板。
Does anybody have an idea how to get my logs from my custom container using client.containers.run ?有人知道如何使用client.containers.run从我的自定义容器中获取我的日志吗?
After several days of research, I am able to provide additional information isolating the issue.经过几天的研究,我能够提供额外的信息来隔离这个问题。
C++ testApp Code Sample: 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 content: DockerFile 内容:
FROM amd64/ubuntu:latest
ADD / test
WORKDIR /test
RUN chmod +x testApp
ENTRYPOINT ["/test/testApp"]
Python Code 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)
To summarize, when running my custom container from command line docker run -it test
, I have got the logs but when running it with docker-py with dockerClient.containers.run
, My logs stays empty.总而言之,当从命令行docker run -it test
运行我的自定义容器时,我得到了日志,但是当使用 docker -py和dockerClient.containers.run
运行它时,我的日志保持为空。
Does anybody have an idea how to get my logs from my custom container using dockerClient.containers.run
?有人知道如何使用dockerClient.containers.run
从我的自定义容器中获取我的日志吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.