I'm using Python to run local shell command, with "subprocess":
subprocess.call("docker exec -it transcoder /bin/bash", shell=True, stdout=output, stderr=output)
subprocess.call("ffmpeg", shell=True, stdout=output, stderr=output)
The two command above which run step by step manually will like :
#first command executed
#docker exec -it transcoder /bin/bash output as :
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
root@85fe13a:/#
Those I describe it as it has changed the session context, so that the next command run within the new context, manual run next command, like:
#2nd command executed
root@85fe13a:/# ffmpeg
ffmpeg version n4.3-dev-3911-g00afeaf548 Copyright .....
Okay, let's run in Python:
s = """
docker exec -it transcoder /bin/bash
ffmpeg
"""
subprocess.run([s], shell=True)
The output will be like:
#docker exec -it transcoder /bin/bash output as :
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
root@85fe13a:/#
The command 'ffmpeg' seems not to work!
I want run new command continually after first command done. Since I have test the command as below which runs well as expected:
s = """
cd /www/pathDir
ls
"""
subprocess.run([s], shell=True)
but now my case not work, what's difference between these two cases and can subprocess or Python will work in any pattern as I expected?
After days of environment's fix and fix, then the Docker library in Python installed correctly; we use it to run commands as follows:
import docker
client = docker.DockerClient(base_url='unix://var/run/docker.sock')
c = client.containers.run('image', detach=True, tty = True, volumes = {
'/www' : {
'bind' : '/www',
'mode' : 'rw'
}
print(c.logs(), c.exec_run( "ffmpeg -i /www/xxx.MP4" ))
But another way like: docker exec -it transcoder ffmpeg also works well.
python docker lib Can't open an interactive container
Thanks @David Maze !
That's all from a Docker beginner.
dockerandffmpegsequentially in the same, local shell, rather theffmpegcommand is run in the interactive shell you get fromdocker -it /bin/bash. You could runffmpegdirectly instead ofbash.docker execin routine work. (It brings all of the complications and permission issues around using Docker, plus it's not the "normal" path to run a container so you won't be able to see things like the process output.) Can you installffmpeglocally and just usesubprocess.call(['ffmpeg', ...])? (There are serious security problems aroundshell=True, avoid it if at all possible.)ffmpegin it.