Docker-py: access to python script output is done in the ENTRYPOINT command

I'm having trouble getting output to a Python script. I start in the docker container using the docker-py module in Python.

First, some context:

I created a Docker file and built my image (with id 84730be6107f) in the usual way via the command line ( docker build -t myimage /path/to/dockerfile). The Python script is executed as a command ENTRYPOINTin the Docker file:

ENTRYPOINT ["python", "/cont_dirpath/script.py"]

The directory containing the script is added (attached) to the container when it starts.

When I do this using the regular docker command line (on Ubuntu), using:

docker run -v /host_dirpath:/cont_dirpath 84730be6107f

I get the expected Python script output printed on stdout (displayed in the terminal - the script ends with a command print result). This is exactly the result I am trying to get by executing this from Python.

However, trying to do this from Python using the docker-py package, I cannot see the results - the method logsreturns an empty string. Here is the Python code I'm using:

from docker import Client

docker = Client(base_url='unix://var/run/docker.sock',
                  version='1.10',
                  timeout=10)

contid = docker.create_container('84730be6107f', volumes={"/cont_dirpath":""})
docker.start(contid, binds={"/host_dirpath": {"bind": "/cont_dirpath"} })

print "Docker logs: \n" + str(docker.logs(contid))

I just get an empty string. I tried to connect the output of the script to echoand catin the command ENTRYPOINT, but to no avail. How can I get the script.py run output in a command ENTRYPOINTto be part of the log for this container so that I can read it using the docker-py Python methods? I also tried the docker-py method attach(I think that logsthis is only a complete version) with the same result.

script stdout, , docker-py.

!

+4

Source: https://habr.com/ru/post/1539070/


All Articles