I am having some difficulty trying to create a script which creates and builds a docker file that gets the current users uid and gid and sets the user vagrant's uid and gid inside of container to match the host.
output = "FROM %s\nUSER root\nRUN usermod --uid %s vagrant && groupmod --gid %s vagrant && chown -R vagrant:vagrant /home/vagrant\nUSER vagrant" % (build_image, uid, gid)
f = open("Dockerfile", "w")
f.write(output)
f.close
# Build the image using the created Dockerfile
build_command = "docker build -t %s . --pull" % args.name
print("\nRunning: " + build_command)
subprocess.call(['bash', '-c', build_command])
docker build -t test-image . --pull works on the command line but when running the script I get: "Error response from daemon: the Dockerfile (Dockerfile) cannot be empty"
Does anyone have any ideas why this might be happening?
['bash', '-c', cmd]is just a roundabout way of reimplementingcmd, shell=True. You want to avoid both; pass['docker', 'build', '-t', args.name, '.', '--pull']directly.