What is the difference between an image and a repository?

前端 未结 5 1575
既然无缘
既然无缘 2021-01-31 08:30

I am brand new to Docker and following the Getting Started tutorial. At step 7 it says

type docker images command and press RETURN. The comma

5条回答
  •  有刺的猬
    2021-01-31 08:39

    Quoted from the official Docker documentation:

    A repository potentially holds multiple variants of an image.

    (see: https://docs.docker.com/userguide/dockerimages)

    This means: A Docker image can belong to a repository, e.g. when it was pushed to a Docker registry (with docker push my/reporitory:version1). On the other side, a repository contains multiple versions of an image (= different tags). So when you build an new version of your image, you can give it a tag (docker tag 518a41981a6a my/reporitory:version2) and push it to your repository as the next version (docker push my/reporitory:version2).

    Here's an example from the Docker documentation (see the link above). As you can see, it shows one repository called ouruser/sinatra which contains various versions (latest, devel, v2) of the same image:

    $ docker images ouruser/sinatra
    REPOSITORY          TAG     IMAGE ID      CREATED        VIRTUAL SIZE
    ouruser/sinatra     latest  5db5f8471261  11 hours ago   446.7 MB
    ouruser/sinatra     devel   5db5f8471261  11 hours ago   446.7 MB
    ouruser/sinatra     v2      5db5f8471261  11 hours ago   446.7 MB
    

    In your example, you have two repositories (docker/whalesay and hello-world) which only contains one tagged image (called latest, which just means there is not tag actually and the latest images is shown).

提交回复
热议问题