I am trying to run this docker function in Juypter Notebook:
subprocess.run(["docker", "run", "--rm", "-t", "--name", "stream", "-v", "/home/benson/OCR_project:/user-data/", "--user", "id -u:`id -g`", "-e", f"LICENSE_KEY={license_key}", "-e", f"TOKEN={token}", "platerecognizer/alpr-stream"])
Which is from here: https://platerecognizer.com/
I am trying to do this in a while loop, but when I try and run the subprocess, even just in a Juypter notebook cell outside of the while loop to check its working, I get this error:
CompletedProcess(args=['docker', 'run', '--rm', '-t', '--name', 'stream', '-v', '/home/benson/OCR_project:/user-data/', '--user', 'id -u:`id -g`', '-e', 'LICENSE_KEY=sB6WCDvshT', '-e', 'TOKEN=80cc7ff865e421cde42a2df9ae165f5f5482b5a5', 'platerecognizer/alpr-stream'], returncode=125)
125 means error, and nothing runs, but I was looking for some guidance. I'm not very fluent with running terminal commands in Juypter and a while loop.
Your problem is with:
"--user", "id -u:`id -g`"
This looks like an attempt to retrieve your UID and GID using the commands id -u
and id -g
. The id -g
is enclosed in back ticks, which are used to tell the shell to execute the enclosed command and then replace the command with the command's output. For this to work, the id -u
would also need to be enclosed in back ticks. However you are not executing the command from a shell. You can use two more python commands to get the UID and GID and then pass them to the subprocess.run(...)
command:
import os
import subprocess
gid = os.getegid()
uid = os.geteuid()
subprocess.run(["docker", "run", "--rm", "-t", "--name", "stream", "-v", "/home/benson/OCR_project:/user-data/", "--user", f"{uid}:{gid}", "-e", f"LICENSE_KEY={license_key}", "-e", f"TOKEN={token}", "platerecognizer/alpr-stream"])