In python with docker-py, I am running two docker containers:
I use the following 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
After several tests this is my findings:
The same tests with eclipse-mosquitto gives me always a Docker Desktop Dashboard full of logs.
Does anybody have an idea how to get my logs from my custom container using client.containers.run ?
After several days of research, I am able to provide additional information isolating the issue.
C++ testApp Code Sample:
#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:
FROM amd64/ubuntu:latest
ADD / test
WORKDIR /test
RUN chmod +x testApp
ENTRYPOINT ["/test/testApp"]
Python Code
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.
Does anybody have an idea how to get my logs from my custom container using dockerClient.containers.run
?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.