docker / docker-py

A Python library for the Docker Engine API
https://docker-py.readthedocs.io/
Apache License 2.0
6.79k stars 1.67k forks source link

multiple images were pulled by one command #2231

Open horitaku1124 opened 5 years ago

horitaku1124 commented 5 years ago

Hello

I referred this page Docker SDK for Python. I execute these sample command, but I got many images by one command.

python3
Python 3.7.1 (default, Nov 28 2018, 11:51:47) 
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
>>> client = docker.from_env()
>>> client.containers.run("ubuntu", "echo hello world")

after 1minutes, I got 4 ubuntu images

ubuntu              12.04               5b117edd0b76        21 months ago       104MB
ubuntu              12.04.5             5b117edd0b76        21 months ago       104MB
ubuntu              12.10               3e314f95dcac        4 years ago         172MB
ubuntu              10.04               e21dbcc7c9de        4 years ago         183MB

I am using macOS 10.14.2, Docker Desktop CE Version 2.0.0.2 (30215)

dsseng commented 5 years ago

Related: #953

shin- commented 5 years ago

Yes, this is related to #953. While the behavior for pull is consistent with the API's design, as explained in #953, it's obvious that in the case of run, only latest should be pulled if the tag is omitted.

Tset-Noitamotua commented 5 years ago

Actual

Given I have not pulled mongo image manually (e.g. with docker cli)
When I execute the code below
Then ALL available mongo images will be downloaded

image

Expected

Given I don't specify an image tag to the `run` command
When I execute the code below
Then only the mongo:latest image is downloaded 

Code Example

import docker
client = docker.from_env()

def run_mongodb_container():
    """run a mondodb container in background"""
    container = client.containers.run("mongo", name="MongoDB",
                                        ports={'27017/tcp': 27017},
                                        detach=True)
    container = client.containers.get("MongoDB")
    logs = container.logs()
    return logs