简体   繁体   中英

How to save a Docker image

I'm trying to follow a tutorial on https://www.ctl.io/developers/blog/post/docker-networking-rules/ , which contains the following:

在此处输入图片说明

As I understand it, the code

FROM ubuntu:trusty
MAINTAINER Laura Frank <laura.frank@centurylink.com>
CMD while true; do echo 'hello world' | nc -l -p 8888; done

Is the content of a Dockerfile , which can be put in a newly created, empty directory and build using the command docker build . .

I don't quite understand however how to 'name' the image no-exposed-ports ? Am I supposed to use tagging (the -t option) as in the example in https://docs.docker.com/engine/tutorials/dockerimages/ ?

I believe that by 'naming' the Docker image it is indeed meant that you use a tag. I used the command

docker build -t no-exposed-ports .

which gives the following response:

Sending build context to Docker daemon 2.048 kB
Step 1 : FROM ubuntu:trusty
 ---> 3f755ca42730
Step 2 : CMD while true; do echo 'hello world' | nc -l -p 8888; done
 ---> Using cache
 ---> b8a7551d0ed9
Successfully built b8a7551d0ed9

From the command docker images I can see that no-exposed-ports is the name of the REPOSITORY , and the default tag latest has been assigned:

REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
no-exposed-ports                 latest              b8a7551d0ed9        18 minutes ago      188 MB

Finally, running with the command

docker run -d --name no-exposed-ports no-exposed-ports

produces a long hash as in the example on the blog:

eb39d8ef68826510f4c964ad586ff04b9e334433538d9d69a39aa0ec44d6701f

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM