docker 常用命令 镜像篇

1.创建镜像build

[root@worker1 ~]# docker image build -t harbor.rzl.com/test/nginx:v1  .
Sending build context to Docker daemon  130.8MB
Step 1/6 : FROM nginx
 ---> 2622e6cca7eb
Step 2/6 : ENV LANGUAGE en_US.utf8
 ---> Running in 14c9f9fec2bb
Removing intermediate container 14c9f9fec2bb
 ---> 6fc071080f58
Step 3/6 : ENV LANG en_US.utf8
 ---> Running in e7a55ee7fb8d
Removing intermediate container e7a55ee7fb8d
 ---> dcb843f50dba
..............................

2.下载镜像

[root@worker1 ~]# docker pull nginx:1.14
1.14: Pulling from library/nginx
27833a3ba0a5: Downloading [======================================>            ]  17.36MB/22.5MB
0f23e58bd0b7: Downloading [=========================================>         ]  18.48MB/22.2MB
8ca774778e85: Download complete 

3.查看镜像

[root@worker1 ~]# docker image ls

4.查看镜像分层

[root@worker1 ~]# docker image history 2622e6cca7eb 
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
2622e6cca7eb        3 weeks ago         /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  STOPSIGNAL SIGTERM           0B                  
<missing>           3 weeks ago         /bin/sh -c #(nop)  EXPOSE 80                    0B                  
...................
[root@worker1 ~]# docker image inspect 2622e6cca7eb
[
    {
        "Id": "sha256:2622e6cca7ebbb6e310743abce3fc47335393e79171b9d76ba9d4f446ce7b163",
        "RepoTags": [],
        "RepoDigests": [
            "nginx@sha256:21f32f6c08406306d822a0e6e8b7dc81f53f336570e852e25fbe1e3e3d0d0133"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2020-06-09T16:57:42.632836191Z",
        "Container": "53e54c20f21e263548ac09475373e20dfef58dd38aebc6caec258b4ff6c2446c",
        "ContainerConfig": {
            "Hostname": "53e54c20f21e",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}

5.打tag(一般用于上传至自己的私服)

[root@worker1 ~]# docker image tag portainer/portainer:latest  harbor.rzl.com/library/portainer:latest

6.删除镜像

[root@worker1 ~]# docker image ls
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
nginx                              <none>              2622e6cca7eb        3 weeks ago         132MB
nginx                              latest              9beeba249f3e        7 weeks ago         127MB
nginx                              <none>              602e111c06b6        2 months ago        127MB
portainer/portainer                latest              2869fc110bf7        3 months ago        78.6MB
harbor.rzl.com/library/portainer   latest              2869fc110bf7        3 months ago        78.6MB
[root@worker1 ~]# docker image  rm 602e111c06b6
Untagged: nginx@sha256:86ae264c3f4acb99b2dee4d0098c40cb8c46dcf9e1148f05d3a51c4df6758c12
Deleted: sha256:602e111c06b6934013578ad80554a074049c59441d9bcd963cb4a7feccede7a5
Deleted: sha256:81eaddad75aaa517b4a597912da28c2f5b905f6e9789dce3aea874b040aad201
Deleted: sha256:73cafa8418003ecfaa02360f181c132b2cf4b61433e1bd5c84012941105865c8
Deleted: sha256:c2adabaecedbda0af72b153c6499a0555f3a769d52370469d8f6bd6328af9b13

7.推送镜像

[root@worker1 ~]# docker image push harbor.rzl.com/library/portainer:latest
The push refers to repository [harbor.rzl.com/library/portainer]
0c26382398c3: Pushing [========================>                          ]  38.96MB/78.37MB
dd4969f97241: Pushed 

 8.清理镜像(会将没有关联的镜像清理掉)还可以加加参数-a

[root@worker1 ~]# docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B

 9.保存镜像

[root@worker1 ~]# docker image save -o nginx.tar  nginx:latest 
[root@worker1 ~]# ls
anaconda-ks.cfg  basic.sh  log.log  nginx.tar  portainer

10.导入镜像

[root@worker1 ~]# docker image load < nginx.tar 
ffc9b21953f4: Loading layer [==================================================>]  72.49MB/72.49MB
2f4accd375d9: Loading layer [==================================================>]  58.12MB/58.12MB
6c7de695ede3: Loading layer [==================================================>]  3.584kB/3.584kB
Loaded image: nginx:latest
原文地址:https://www.cnblogs.com/caonw/p/13259325.html