Using docker python library,
UID = USER_ID = os.getuid()
GROUP_ID = os.getgid()
USER = getpass.getuser()
HOME = "~"
DIR = os.getcwd()
DOCKER_GID = execute_shell_command('"$(stat -c "%g" /var/run/docker.sock)"', log_path)
VERSION = "latest"
BASE_DOCKER = "ubuntu:20.04"
assert os.path.isfile(dockerfile_path)
build_args = {
"UID": UID,
"DOCKER_GID": DOCKER_GID,
"UNAME": USER,
"VER": VERSION,
"BASE_IMAGE": BASE_DOCKER,
}
client = client = docker.from_env()
client.images.build(fileobj=dockerfile, buildargs=build_args)
Getting
Bad Request ("error reading build args: json: cannot unmarshal number into Go value of type string")
This is not Googleable, so posting for future readers
Answer was found here
Convert numbers in build_args
to strings to avoid this undocumented error:
build_args = {k: str(v) for k, v in {
"UID": UID,
"DOCKER_GID": DOCKER_GID,
"UNAME": USER,
"VER": VERSION,
"BASE_IMAGE": BASE_DOCKER,
}.items()}