Saad
Saad

Reputation: 954

Docker Container Waiting/Up Time in docker-py library

I am using docker-py (create_container function) to create multiple Docker containers, my code is working properly and creating containers for me and after some time the container exits automatically, but the thing i want to implement here is that, i want all my container to be in running mode for the desired time, for example i want all the containers to be in running mode for 5 minutes or 10 minutes etc etc.. i have added "sleep" in command parameter but it is not working for me, please help ! i am not much experienced in python.. the function i implement is;

for i in range(0,5):
    container = client.create_container(
                    image='syed/syedclients:helloworld',
                    stdin_open=True,
                    tty=True,
                    command='/bin/bash saad.sh /bin/sleep 180',
                    name=hello-1,                    
                    volumes=volumes,
                    host_config=host_config,
                    environment=['VARIABLE=xyz123'],
                    detach=True,
    )
    client.start(container)

Upvotes: 3

Views: 757

Answers (1)

Sergiu
Sergiu

Reputation: 3185

This isn't to do with python, but it is more to do with Docker. The container just does what you have specified, which is: run the script and exit. Therefore, I would suggest that you add the sleep command to the 'saad.sh' script

Upvotes: 2

Related Questions