0

Based on this tutorial to build a TF image classifier, I have a bash shell in which I run a Docker image with the following command:

docker run --name fooldocker -it -v $HOME/tf_files:/tf_files/ gcr.io/tensorflow/tensorflow:latest-devel

And then in this docker image I run my Python script:

python /tf_files/label_image.py /tf_files/myimages
exit

It works.

But now, I need to automate these commands in a Python script. I tried :

p = Popen(['docker', 'run', '--rm', '--name', 'fooldocker','-it', '-v', '$HOME/tf_files:/tf_files/', 'gcr.io/tensorflow/tensorflow:latest-devel'], stdout=PIPE)
p = Popen(['docker', 'exec', 'fooldocker', 'python', '/tf_files/label_NES.py', '/tf_files/NES/WIP'])
p = Popen(['docker', 'kill', 'fooldocker'], shell=True, stdout=PIPE, stderr=PIPE)
p = Popen(['docker', 'rm', 'fooldocker'], shell=True, stdout=PIPE, stderr=PIPE)

Leading to this error after Popen #2 is run :

docker: Error response from daemon: create $HOME/tf_files: "$HOME/tf_files" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.

2 Answers 2

1

The problem is that $HOME cannot be evaluated in this single quotes string. Either try doublequotes, or evaluate the variable beforehand and put it into the command string.

Also: If you set shell=True, you don't split your command into a list:

p = Popen('docker kill fooldocker', shell=True, stdout=PIPE, stderr=PIPE)
Sign up to request clarification or add additional context in comments.

Comments

0

it is because Popen didn't interpret $HOME to your home path. and it is the string $HOME and pass to docker command which not allow $ in a volume name.

maybe you can use subprocess module for convenience, for example:

import subprocess
subprocess.call("echo $HOME", shell=True)

it interpreted $HOME if shell=True specified.

2 Comments

Popen is a part of the subprocess module ;)
oh, yes, I forgot it belongs to subprocess too. Use wrappered functions too often :|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.