w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Issue with docker-py in executing /bin/bash

The difference is you're in tty (-t) mode with an open stdin (-i) when you run your docker image with docker run -t -i p14 /startup.sh, whereas you set both stdin_open=False and tty=False in your docker-py configuration.

Because your docker container has no tty and can't take any input from stdin, your call to /bin/bash has nothing to do so exits with code 0.

Try it yourself:

An open stdin with a tty

$ docker run -t -i ubuntu:14.04 /bin/bash                       
          
root@1e7eda2bba03:/# ls -la                                                
total 7184                                                                 
drwxr-xr-x  21 root root    4096 Sep 19 21:30 .                            
drwxr-xr-x  21 root root    4096 Sep 19 21:30 ..                           
-rwxr-xr-x   1 root root       0 Sep 19 21:30 .dockerenv                   
-rwx------   1 root root 7279686 Jul 21 10:50 .dockerinit                  
drwxr-xr-x   2 root root    4096 Sep  3 03:33 bin                          
drwxr-xr-x   2 root root    4096 Apr 10 22:12 boot                         
drwxr-xr-x   4 root root     360 Sep 19 21:30 dev                          
drwxr-xr-x  61 root root    4096 Sep 19 21:30 etc                          
drwxr-xr-x   2 root root    4096 Apr 10 22:12 home                         
drwxr-xr-x  12 root root    4096 Sep  3 03:33 lib                          
drwxr-xr-x   2 root root    4096 Sep  3 03:33 lib64                        
drwxr-xr-x   2 root root    4096 Sep  3 03:33 media                        
drwxr-xr-x   2 root root    4096 Apr 10 22:12 mnt                          
drwxr-xr-x   2 root root    4096 Sep  3 03:33 opt                          
dr-xr-xr-x 240 root root       0 Sep 19 21:30 proc                         
drwx------   2 root root    4096 Sep  3 03:33 root                         
drwxr-xr-x   7 root root    4096 Sep  3 03:33 run                          
drwxr-xr-x   2 root root    4096 Sep  4 18:41 sbin                         
drwxr-xr-x   2 root root    4096 Sep  3 03:33 srv                          
dr-xr-xr-x  13 root root       0 Sep 19 18:44 sys                          
drwxrwxrwt   2 root root    4096 Sep  4 18:41 tmp                          
drwxr-xr-x  10 root root    4096 Sep  3 03:33 usr                          
drwxr-xr-x  11 root root    4096 Sep  3 03:33 var                          
root@1e7eda2bba03:/#  

An open stdin with no tty (i.e., no prompt, but you can still send commands via stdin)

$ docker run -i ubuntu:14.04 /bin/bash                          
          
ls -la                                                                     
total 7184                                                                 
drwxr-xr-x  21 root root    4096 Sep 19 21:32 .                            
drwxr-xr-x  21 root root    4096 Sep 19 21:32 ..                           
-rwxr-xr-x   1 root root       0 Sep 19 21:32 .dockerenv                   
-rwx------   1 root root 7279686 Jul 21 10:50 .dockerinit                  
drwxr-xr-x   2 root root    4096 Sep  3 03:33 bin                          
drwxr-xr-x   2 root root    4096 Apr 10 22:12 boot                         
drwxr-xr-x   4 root root     340 Sep 19 21:32 dev                          
drwxr-xr-x  61 root root    4096 Sep 19 21:32 etc                          
drwxr-xr-x   2 root root    4096 Apr 10 22:12 home                         
drwxr-xr-x  12 root root    4096 Sep  3 03:33 lib                          
drwxr-xr-x   2 root root    4096 Sep  3 03:33 lib64                        
drwxr-xr-x   2 root root    4096 Sep  3 03:33 media                        
drwxr-xr-x   2 root root    4096 Apr 10 22:12 mnt                          
drwxr-xr-x   2 root root    4096 Sep  3 03:33 opt                          
dr-xr-xr-x 243 root root       0 Sep 19 21:32 proc                         
drwx------   2 root root    4096 Sep  3 03:33 root                         
drwxr-xr-x   7 root root    4096 Sep  3 03:33 run                          
drwxr-xr-x   2 root root    4096 Sep  4 18:41 sbin                         
drwxr-xr-x   2 root root    4096 Sep  3 03:33 srv                          
dr-xr-xr-x  13 root root       0 Sep 19 18:44 sys                          
drwxrwxrwt   2 root root    4096 Sep  4 18:41 tmp                          
drwxr-xr-x  10 root root    4096 Sep  3 03:33 usr                          
drwxr-xr-x  11 root root    4096 Sep  3 03:33 var   

A closed stdin with a tty (you can see the prompt but you can't enter any commands)

$ docker run -t ubuntu:14.04 /bin/bash
root@95904c21e5a5:/# ls -la
hello
this does nothing :(

A closed stdin with no tty - /bin/bash has nothing to do

$ docker run ubuntu:14.04 /bin/bash
$ 




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.