What is the difference between an image and a repository?

前端 未结 5 1567
既然无缘
既然无缘 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:57

    It's easiest to define several terms here because they all interrelate:

    Image: This is the filesystem layers and metadata used to package an application in a way to run containers. Each image must have an ID on a docker engine.

    Reference: This is a pointer to an image. There are different types of references, either just the image ID, usually the it is a repository and tag, and sometimes you will pin to a specific checksum using a sha256 hash instead of a changeable tag. The important part is that you can have multiple pointers to the same image, and that it is not necessary to have any references to an image other than the image ID. When you delete a reference, docker will just delete that pointer unless it was the last pointer to that image ID.

    Registry: This is a server that holds images. Similar to how a Git server holds source code, or an artifact server for binaries, a registry is where you push and pull images to and from.

    Repository: The path to a directory of images on a registry server is the repository. This includes the registry hostname and port if you aren't using the default Docker Hub registry. In an image reference, this repository is the part before the final colon and tag.

    Tag: A specific image within a repository. If you do not specify a tag, docker will default to the tag name "latest". This is the part after the final colon, and is often used for a version number.


    To take an example reference:

    registry-server:5000/team/service-a:build-42
    
    • "registry-server:5000" is the registry server name (and port) where you would push/pull this image.

    • "registry-server:5000/team/service-a" is the repository.

    • "build-42" is the tag.

    • "registry-server:5000/team/service-a:build-42" is a reference.

    Unlike other systems where you push and pull to a server and then specific what files to send there, pushing and pulling docker images to and from a registry server defines the destination and source of the image using a reference that includes the repository and tag in that name. So to push images to a different location, you create a new reference (using the docker tag command) to the same image with the new repository and tag, and then run your push command against that reference.

    Typically when someone refers to an "image name" they are referring to either a repository name (if you want to specify a tag separately) or a complete reference that you can use to pull or push an image.


    how can I just list my repositories?

    docker image ls --format '{{.Repository}}' | sort -u
    

    I included the sort -u to de-dup the output since you may have multiple images with the same repository and different tags.

提交回复
热议问题