0

使用 docker python 库,


    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)

得到

Bad Request ("error reading build args: json: cannot unmarshal number into Go value of type string")
4

1 回答 1

0

这不是谷歌的,所以发布给未来的读者

在这里找到了答案

将数字转换build_args为字符串以避免此未记录的错误:

 build_args = {k: str(v) for k, v in {
        "UID": UID,
        "DOCKER_GID": DOCKER_GID,
        "UNAME": USER,
        "VER": VERSION,
        "BASE_IMAGE": BASE_DOCKER,
    }.items()} 
于 2022-02-06T19:35:49.587 回答