Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python run docker interactively subprocess

run_this = "print('hi')"
random_name = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(20))
command = 'docker run -i -t --name="%s" dockerfile/python /bin/bash' % random_name
subprocess.call([command],shell=True,stderr=subprocess.STDOUT)
command = 'cat <<'PYSTUFF' | timeout 0.5 python | head -n 500000 
%s
PYSTUFF' % run_this
output = subprocess.check_output([command],shell=True,stderr=subprocess.STDOUT)
command = 'exit'
subprocess.call([command],shell=True,stderr=subprocess.STDOUT)
command = 'docker ps -a | grep "%s" | awk "{print $1}" | xargs --no-run-if-empty docker rm -f' % random_name
subprocess.call([command],shell=True,stderr=subprocess.STDOUT)
Comment

python run docker interactively subprocess

from subprocess import Popen, PIPE

p = Popen("docker run -i -t --name="%s" dockerfile/python /bin/bash", stdin=PIPE)
p.communicate("timeout 0.5 python | head -n 500000 
" % run_this)
Comment

docker python run subprocess python run docker interactively subprocess

import pty
import sys
import select
import os
import subprocess

pty, tty = pty.openpty()

p = subprocess.Popen(['docker', 'run', '-it', '--rm', 'ubuntu', 'bash'], stdin=tty, stdout=tty, stderr=tty)

while p.poll() is None:
    # Watch two files, STDIN of your Python process and the pseudo terminal
    r, _, _ = select.select([sys.stdin, pty], [], [])
    if sys.stdin in r:
        input_from_your_terminal = os.read(sys.stdin.fileno(), 10240)
        os.write(pty, input_from_your_terminal)
    elif pty in r:
        output_from_docker = os.read(pty, 10240)
        os.write(sys.stdout.fileno(), output_from_docker)
Comment

docker python run subprocess python run docker interactively subprocess

import os
os.system('docker run -it --rm ubuntu bash')
Comment

PREVIOUS NEXT
Code Example
Python :: Python NumPy squeeze function Syntax 
Python :: Algorithm of Broadcasting with NumPy Arrays 
Python :: Python NumPy atleast_3d Function Example when inputs are high dimesion 
Python :: Python NumPy transpose Function Example in one line of code 
Python :: Python NumPy ndarray flat function Example 
Python :: no definition 
Python :: text xml 
Python :: find duplicate row in python sqlite database 
Python :: how to convrete .npz file to txt file in python 
Python :: Python NumPy asarray_chkfinite Function Example Tuple to an array 
Python :: Python NumPy dstack Function Example 02 
Python :: vocal remover source code python 
Python :: fpdf latin-1 
Python :: add text to pdf file in python 
Python :: Python how to use __ne__ 
Python :: p0, percent, aug (inhabitants coming or leaving each year), p (population to surpass) 
Python :: import date formater 
Python :: lambda function in python to shut ec2 at the time zone 
Python :: selenium python select elements data atribute 
Python :: gensim prepare corpus 
Python :: Accessing range() with index value 
Python :: cv2 recize 
Python :: python random number between 1000 and 9999 
Python :: python readlines  
Python :: tkinter screen clicked 
Python :: Flask - how do I combine Flask-WTF and Flask-SQLAlchemy to edit db models 
Python :: python 3.9.13 release date 
Python :: sns.kdeplot make line more detailed 
Python :: text to ascii art generator python 
Python :: plot a list of number in python 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =