Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

docker.pull("imagename") causes docker daemon to pull all known tags of the image #873

Open
mattnworb opened this issue Aug 24, 2017 · 6 comments
Labels
help wanted pinned exempt from being marked as stale

Comments

@mattnworb
Copy link
Member

As seen in #857 (comment), pulling the name of an image repository without specifying a tag (such as dockerClient.pull("redis")) causes the docker daemon to pull all the tags that it can find of that image.

When dockerClient.pull("redis") is called, the client sends a request to the Docker Remote API like POST /images/create?fromImage=redis.

When no tag parameter is specified for the image pull/create, it seems like the daemon will try to pull all known tags from the repository, which appears to be behavior that isn't quite documented (but then again it is not clear which image should be pulled for this request).

When you do docker pull redis from the command line, the docker-cli sends the request POST /images/create?fromImage=redis&tag=latest - it interprets the tag-less image request as being :latest implicitly, but our DockerClient doesn't do the same.

It would probably make more sense for DefaultDockerClient to quietly interpret an image pull like "redis" as "redis:latest" to behave the same as docker pull, rather than sending POST /images/create?fromImage=redis to pull all known tags.

@johnflavin
Copy link
Contributor

Might be helpful to tag this issue with "Help Wanted". It could be an easy PR for a new contributor.

@davidxia
Copy link
Contributor

@mattnworb This behavior is documented in recent API versions.

Tag or digest. If empty when pulling an image, this causes all tags for the given image to be pulled.

Do we still want to mimic the behavior of the docker CLI? I think we should stick with the current behavior. It matches the docs. Moreover, defaulting to pulling the "latest" tag when there's no tag specified could lead to errors ("latest" tag doesn't exist), breaks backwards compatibility, and then there's no way to pull all the tags easily.

@mattnworb
Copy link
Member Author

It is hard to say what the user intent is if they call docker.pull("redis"). I can't really see a use case for pulling all known tags of a given docker repository. If we assume they mean docker.pull("redis:latest") then it seems reasonable to throw an error if redis:latest doesn't exist.

What happens if you try to create a container from a tagless image, like "redis"?

@davidxia
Copy link
Contributor

Seems like this code will run the same image when IMAGE is "nginx" or "nginx:latest". docker inspect shows both containers have the same image sha256:40960efd7b8f44ed5cafee61c189a8f4db39838848d41861898f56c29565266e`.

    final DockerClient client = DefaultDockerClient.fromEnv().build();
    final ContainerConfig config = ContainerConfig.builder()
        .image(IMAGE)
        .portSpecs()
        .build();
    final ContainerCreation container = client.createContainer(config);
    client.startContainer(container.id());
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS               NAMES
6ad6718144a6        nginx:latest        "nginx -g 'daemon ..."   10 seconds ago       Up 9 seconds        80/tcp              dazzling_rosalind
2c271bc7dbee        nginx               "nginx -g 'daemon ..."   46 seconds ago       Up 45 seconds       80/tcp              keen_blackwell

[
    {
        "Id": "6ad6718144a61e91fb00b73aa16b428368c41adb151f36b181b39c10e97dc5f0",
        "Created": "2017-11-15T20:14:16.067284927Z",
        "Path": "nginx",
        "Args": [
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 20380,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-11-15T20:14:16.574460722Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:40960efd7b8f44ed5cafee61c189a8f4db39838848d41861898f56c29565266e",
        "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/6ad6718144a61e91fb00b73aa16b428368c41adb151f36b181b39c10e97dc5f0/resolv.conf",
        "HostnamePath": "/mnt/sda1/var/lib/docker/containers/6ad6718144a61e91fb00b73aa16b428368c41adb151f36b181b39c10e97dc5f0/hostname",
        "HostsPath": "/mnt/sda1/var/lib/docker/containers/6ad6718144a61e91fb00b73aa16b428368c41adb151f36b181b39c10e97dc5f0/hosts",
        "LogPath": "/mnt/sda1/var/lib/docker/containers/6ad6718144a61e91fb00b73aa16b428368c41adb151f36b181b39c10e97dc5f0/6ad6718144a61e91fb00b73aa16b428368c41adb151f36b181b39c10e97dc5f0-json.log",
        "Name": "/dazzling_rosalind",
        "RestartCount": 0,
        "Driver": "aufs",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": null,
            "Name": "aufs"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "6ad6718144a6",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.13.6-1~stretch",
                "NJS_VERSION=1.13.6.0.1.14-1~stretch"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "ArgsEscaped": true,
            "Image": "nginx:latest",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <[email protected]>"
            },
            "StopSignal": "SIGTERM"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "693737dd8cbe6d11b75a5515990dd11ae37e7ebf7b86ece89a1f6a7c6aef0c97",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/693737dd8cbe",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "17b36699fbb8bf1ed67de0e3e183618dde1a2e17b38b43405b8806583e21585e",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.4",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:04",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "04531838bc74f47e7ee739123c0a4a7e5845f87af1f54c1c65ed7a6def3c8c3d",
                    "EndpointID": "17b36699fbb8bf1ed67de0e3e183618dde1a2e17b38b43405b8806583e21585e",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.4",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:04",
                    "DriverOpts": null
                }
            }
        }
    }
]

[
    {
        "Id": "2c271bc7dbeeb702d9eddfb17b6649e7a052a58affc62363a1e342ae57a3c0fc",
        "Created": "2017-11-15T20:13:40.218117823Z",
        "Path": "nginx",
        "Args": [
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 20308,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-11-15T20:13:40.716475827Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:40960efd7b8f44ed5cafee61c189a8f4db39838848d41861898f56c29565266e",
        "ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/2c271bc7dbeeb702d9eddfb17b6649e7a052a58affc62363a1e342ae57a3c0fc/resolv.conf",
        "HostnamePath": "/mnt/sda1/var/lib/docker/containers/2c271bc7dbeeb702d9eddfb17b6649e7a052a58affc62363a1e342ae57a3c0fc/hostname",
        "HostsPath": "/mnt/sda1/var/lib/docker/containers/2c271bc7dbeeb702d9eddfb17b6649e7a052a58affc62363a1e342ae57a3c0fc/hosts",
        "LogPath": "/mnt/sda1/var/lib/docker/containers/2c271bc7dbeeb702d9eddfb17b6649e7a052a58affc62363a1e342ae57a3c0fc/2c271bc7dbeeb702d9eddfb17b6649e7a052a58affc62363a1e342ae57a3c0fc-json.log",
        "Name": "/keen_blackwell",
        "RestartCount": 0,
        "Driver": "aufs",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": null,
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": null,
            "Name": "aufs"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "2c271bc7dbee",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "NGINX_VERSION=1.13.6-1~stretch",
                "NJS_VERSION=1.13.6.0.1.14-1~stretch"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "ArgsEscaped": true,
            "Image": "nginx",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <[email protected]>"
            },
            "StopSignal": "SIGTERM"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "bf3b4045f7529957d732fa72d4fafecd29a96a6a2b5feaff0a2edb2021b3b6ba",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/bf3b4045f752",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "54178cd0ca7eb75936de5a03ea276a3dc0a39d5adeda52ba922a5dc13d8cafc1",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "04531838bc74f47e7ee739123c0a4a7e5845f87af1f54c1c65ed7a6def3c8c3d",
                    "EndpointID": "54178cd0ca7eb75936de5a03ea276a3dc0a39d5adeda52ba922a5dc13d8cafc1",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]

@christophsturm
Copy link

this should maybe be documented in the readme file.
also if i do a pull with the commandline docker command it defaults to latest

~/Projects% docker pull yukinying/chrome-headless-browser-selenium     
Using default tag: latest

docker pull just hang for me and i was going to submit a bug about it when i found this ticket.

@stale
Copy link

stale bot commented Sep 24, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 24, 2018
@davidxia davidxia added pinned exempt from being marked as stale and removed stale labels Sep 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted pinned exempt from being marked as stale
Projects
None yet
Development

No branches or pull requests

4 participants