How can I use a local image as the base image with a dockerfile?

前端 未结 4 1297
春和景丽
春和景丽 2020-12-12 23:22

I\'m working on a dockerfile. I just realised that I\'ve been using FROM with indexed images all along.

So I wonder:

  • How can I use one of
4条回答
  •  春和景丽
    2020-12-12 23:46

    You can have - characters in your images. Assume you have a local image (not a local registry) named centos-base-image with tag 7.3.1611.

    docker version 
          Client:
           Version:         1.12.6
           API version:     1.24
           Package version: docker-common-1.12.6-16.el7.centos.x86_64
           Go version:      go1.7.4
    
          Server:
           Version:         1.12.6
           API version:     1.24
           Package version: docker-common-1.12.6-16.el7.centos.x86_64
           Go version:      go1.7.4
    
    docker images
     REPOSITORY            TAG
     centos-base-image     7.3.1611
    

    Dockerfile

    FROM centos-base-image:7.3.1611
    RUN yum -y install epel-release libaio bc flex
    

    Result

    Sending build context to Docker daemon 315.9 MB
    Step 1 : FROM centos-base-image:7.3.1611
      ---> c4d84e86782e
    Step 2 : RUN yum -y install epel-release libaio bc flex
      ---> Running in 36d8abd0dad9
    ...
    

    In the example above FROM is fetching your local image, you can provide additional instructions to fetch an image from your custom registry (e.g. FROM localhost:5000/my-image:with.tag). See https://docs.docker.com/engine/reference/commandline/pull/#pull-from-a-different-registry and https://docs.docker.com/registry/#tldr

    Finally, if your image is not being resolved when providing a name, try adding a tag to the image when you create it

    This GitHub thread describes a similar issue of not finding local images by name.

    By omitting a specific tag, docker will look for an image tagged "latest", so either create an image with the :latest tag, or change your FROM

提交回复
热议问题