简体   繁体   中英

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)

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM