docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Docker container exits without response or warning

Open RitvikDayal opened this issue 3 years ago • 0 comments

Environment:

  • Python: Python 3.8.10
  • Docker: Docker version 20.10.14, build a224086
  • docker (library): docker-5.0.3

Issue Description:

On running a program inside a container, initialized with 1g of mem_limit, the container exits without any response or warning, or error. I do understand that the program I am running can consume more than 1g in some cases but I need the container to exit with at least some output or status because the connection remains open even if the container has been exited which halts the whole process cycle.

Supporting Code:

# how am I creating the container:
container = self.docker_client.containers.run(
    self.container_name,
    detach=True,
    stderr=True,
    stdout=True,
    tty=True,
    mem_limit="1g",
    runtime='runsc',  # gVisor Runtime
)

# how amI executing the code:
docker_command = self.docker_client.api.exec_create(
    self.container.id,
    "python3 test.py",
)
output = self.docker_client.api.exec_start(
    docker_command,
)

Image and Code:

Docker Image:

FROM python:3.7

COPY . /usr/src/app
WORKDIR /usr/src/app

RUN useradd -ms /bin/bash guest
RUN ["chown", "-R", "guest:guest", "/usr/src/app"]
USER guest

Python code:

This is the code I tried to execute inside the docker container.

  • NOTE: THE CODE IS PURPOSELY WRITTEN TO TEST THE MEMORY CONSUMPTION *
while True:
    for i in range(0,100000000):
        Gig = 1024*1024*1024*1024*2#A Gig multiplied by 2
        a = 999999999999999999999 * (i * Gig)
        a = a * i
        print str(a)*2

Errors / Traceback:

I tried printing and logging but unfortunately, the docker connection never closes and I have to manually interrupt when I can notice a container exited using docker container ls -a.

RitvikDayal avatar Apr 28 '22 07:04 RitvikDayal