Docker Community Forums

Share and learn in the Docker community.

Docker: invalid reference format

Error: docker: invalid reference format.
HOST: Windows 10
Scripting language: Python
docker command used:
runc_vvc_docker_container = ‘docker run -d --name ’ + container_name + ’ --rm -v ’ + mount_dir + ‘:/shared/vvc’ + ’ --privileged -p 2210:2210 -p 8010:8010 ’ + image_to_run + ’ tail -f /dev/null’
print(runc_vvc_docker_container)

output = os.system(runc_vvc_docker_container)
print(output)

Backgroud:
I want to run the container in back-end, and run vvc custom configurations in later stage.(i.e vvc -u -c “custom_config.cfg”)

Strange behavior:
print(runc_vvc_docker_container) results in --> docker run -d --name SWQT --rm -v D:/Work/Blackhole/Azure_Reference_Repo/VRTE_FCs/str-psx-emmc-utils/_qt_project:/shared/vvc --privileged -p 2210:2210 -p 8010:8010 xyz.com/ela7si/vvc:imagename tail -f /dev/null

  1. Above command when run on the windows command prompt manually - it runs with no error.
  2. But when run through python script, results in docker: invalid reference format.

# Working -
subprocess.call('docker run -it --name ’ + container_name + ’ --rm -v ’ + mount_dir + ':/shared/vvc ’ + '–privileged -p 2210:2210 -p 8010:8010 ’ + image_to_run, shell=True)

# Not Working - and also throws Error : docker: invalid reference format.
subprocess.call('docker run -it --name ’ + container_name + ’ --rm -v ’ + mount_dir + ':/shared/vvc ’ + ‘–privileged -p 2210:2210 -p 8010:8010 ’ + image_to_run + ’ tail -f /dev/null’, shell=True)

# Working - runc_vvc_docker_container = 'docker run -d --name ’ + container_name + ’ --rm -v ’ + mount_dir + ‘:/shared/vvc’ + ’ --privileged -p 2210:2210 -p 8010:8010 ’ + image_to_run
os.system(runc_vvc_docker_container)

# Not Working - runc_vvc_docker_container = 'docker run -d --name ’ + container_name + ’ --rm -v ’ + mount_dir + ‘:/shared/vvc’ + ’ --privileged -p 2210:2210 -p 8010:8010 ’ + image_to_run + ’ tail -f /dev/null’
os.system(runc_vvc_docker_container)

Options tried:

  1. shared directory in all small letters
  2. both windows and linux path separator(’/’ and ‘’) and also with double slahses (’//’)
  3. ried with and without interactive (-it) mode

output = os.system(runc_vvc_docker_container)
print(output) --> results in 125 error code.

In this case, the error is most likely from pwd outputting a path with a space in it. Everything after the space is no longer a parameter to -v and docker tries to parse it as the image name. The fix is to quote the volume parameters when you cannot guarantee it is free of spaces or other special characters.