docker镜像的基本操作

查看当前本地镜像

[root@node-03 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              7e4d58f0e5f3        5 days ago          133MB

 

 

[root@node-03 ~]# docker images -a

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              7e4d58f0e5f3        5 days ago          133MB

[root@node-03 ~]#

 

 

 

查看镜像底层信息

[root@node-03 ~]# docker inspect nginx

[

    {

        "Id": "sha256:7e4d58f0e5f3b60077e9a5d96b4be1b974b5a484f54f9393000a99f3b6816e3d",

        "RepoTags": [

            "nginx:latest"

        ],

        "RepoDigests": [

            "nginx@sha256:c628b67d21744fce822d22fdcc0389f6bd763daac23a6b77147d0712ea7102d0"

        ],

        "Parent": "",

        "Comment": "",

        "Created": "2020-09-10T12:33:10.502421624Z",

        "Container": "c72d14cf840a1720d6a3edc1d2217754786d41b89e7afa9f3ca8f1a47e0bb8a7",

        "ContainerConfig": {

            "Hostname": "c72d14cf840a",

            "Domainname": "",

            "User": "",

            "AttachStdin": false,

            "AttachStdout": false,

            "AttachStderr": false,

            "ExposedPorts": {

                "80/tcp": {}

            },

            "Tty": false,

            "OpenStdin": false,

            "StdinOnce": false,

            "Env": [

                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",

                "NGINX_VERSION=1.19.2",

                "NJS_VERSION=0.4.3",

                "PKG_RELEASE=1~buster"

            ],

            "Cmd": [

                "/bin/sh",

                "-c",

                "#(nop) ",

                "CMD [\"nginx\" \"-g\" \"daemon off;\"]"

            ],

            "ArgsEscaped": true,

            "Image": "sha256:fe23bd2ff69e7a6bd80fa4202a69b90c15b49850cef46324611096b4d1c960ff",

            "Volumes": null,

            "WorkingDir": "",

            "Entrypoint": [

                "/docker-entrypoint.sh"

            ],

            "OnBuild": null,

            "Labels": {

                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"

            },

            "StopSignal": "SIGTERM"

        },

        "DockerVersion": "18.09.7",

        "Author": "",

        "Config": {

            "Hostname": "",

            "Domainname": "",

            "User": "",

            "AttachStdin": false,

            "AttachStdout": false,

            "AttachStderr": false,

            "ExposedPorts": {

                "80/tcp": {}

            },

            "Tty": false,

            "OpenStdin": false,

            "StdinOnce": false,

            "Env": [

                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",

                "NGINX_VERSION=1.19.2",

                "NJS_VERSION=0.4.3",

                "PKG_RELEASE=1~buster"

            ],

            "Cmd": [

                "nginx",

                "-g",

                "daemon off;"

            ],

            "ArgsEscaped": true,

            "Image": "sha256:fe23bd2ff69e7a6bd80fa4202a69b90c15b49850cef46324611096b4d1c960ff",

            "Volumes": null,

            "WorkingDir": "",

            "Entrypoint": [

                "/docker-entrypoint.sh"

            ],

            "OnBuild": null,

            "Labels": {

                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"

            },

            "StopSignal": "SIGTERM"

        },

        "Architecture": "amd64",

        "Os": "linux",

        "Size": 132607502,

        "VirtualSize": 132607502,

        "GraphDriver": {

            "Data": {

                "DeviceId": "6",

                "DeviceName": "docker-253:0-17650281-ded07ce4cb9e51538b379bd00d1f0245b96337436bd14a8f5711eb226f9f38f7",

                "DeviceSize": "10737418240"

            },

            "Name": "devicemapper"

        },

        "RootFS": {

            "Type": "layers",

            "Layers": [

                "sha256:07cab433985205f29909739f511777a810f4a9aff486355b71308bb654cdc868",

                "sha256:f431d0917d4154d878551a6b8f716dead84d7ac71601616672a173d67e9edb6c",

                "sha256:60c688e8765e549c1debb75e10b37c9f56528a21c408e15191b36181ac342282",

                "sha256:eabfa4cd2d12ea36b06f20ac0104ceb66b026ea1950de9ec3a80d74d6d8cc54f",

                "sha256:908cf8238301a162a7fc4e2ddb482dacc52d4b96138fbdb18fe8fac30591e852"

            ]

        },

        "Metadata": {

            "LastTagTime": "0001-01-01T00:00:00Z"

        }

    }

]

[root@node-03 ~]#

 

修改镜像标签

 

 

[root@node-03 ~]#

[root@node-03 ~]# docker tag nginx:latest  nginx:v0.1

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              7e4d58f0e5f3        5 days ago          133MB

nginx               v0.1                7e4d58f0e5f3        5 days ago          133MB

[root@node-03 ~]#

 

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              7e4d58f0e5f3        5 days ago          133MB

nginx               v0.1                7e4d58f0e5f3        5 days ago          133MB

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]# docker tag 7e4d58f0e5f3 nginx:v0.2

[root@node-03 ~]#

[root@node-03 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              7e4d58f0e5f3        5 days ago          133MB

nginx               v0.1                7e4d58f0e5f3        5 days ago          133MB

nginx               v0.2                7e4d58f0e5f3        5 days ago          133MB

[root@node-03 ~]#

 

镜像文件保存

镜像文件打包保存在本地;

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]# docker save nginx:latest > nginx.tar

[root@node-03 ~]#

[root@node-03 ~]# ls

anaconda-ks.cfg  ceph-deploy-ceph.log  cluster  nginx.tar

[root@node-03 ~]#

 

 

 删除所有的容器

 

[root@node-03 ~]# docker ps -aq

97378ad966e1

 

[root@node-03 ~]# docker rm -f `docker ps -aq`

97378ad966e1

[root@node-03 ~]#

 

[root@node-03 ~]#

[root@node-03 ~]# docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]#

 

 

删除镜像

 

[root@node-03 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              7e4d58f0e5f3        5 days ago          133MB

nginx               v0.1                7e4d58f0e5f3        5 days ago          133MB

nginx               v0.2                7e4d58f0e5f3        5 days ago          133MB

[root@node-03 ~]# docker rmi nginx:latest

Untagged: nginx:latest

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               v0.1                7e4d58f0e5f3        5 days ago          133MB

nginx               v0.2                7e4d58f0e5f3        5 days ago          133MB

[root@node-03 ~]#

 

[root@node-03 ~]# docker rmi nginx:v0.2

Untagged: nginx:v0.2

Untagged: nginx@sha256:c628b67d21744fce822d22fdcc0389f6bd763daac23a6b77147d0712ea7102d0

Deleted: sha256:7e4d58f0e5f3b60077e9a5d96b4be1b974b5a484f54f9393000a99f3b6816e3d

Deleted: sha256:eedfd37abc0b05520a719addf6675b372687fe9a2ed1746fa988335720d4376c

Deleted: sha256:4f052ddd517f6dc5b74d2f7d881838b8ec6a5e67ec7a1da8bbbe91e1e068ad3a

Deleted: sha256:5f78154d356577280e4ac0d9bf0d021d488828e57f953b011dcbadaecd539ce4

Deleted: sha256:db5783668220e16186080f3e9d69ad748aab8c72abb8e457f6fc45369461634b

Deleted: sha256:07cab433985205f29909739f511777a810f4a9aff486355b71308bb654cdc868

[root@node-03 ~]#

 

 

 

镜像文件导入

 

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]# ls

anaconda-ks.cfg  ceph-deploy-ceph.log  cluster  nginx.tar

[root@node-03 ~]#

[root@node-03 ~]#

[root@node-03 ~]# docker load -i nginx.tar

07cab4339852: Loading layer [==================================================>]  72.49MB/72.49MB

f431d0917d41: Loading layer [==================================================>]  64.31MB/64.31MB

60c688e8765e: Loading layer [==================================================>]  3.072kB/3.072kB

eabfa4cd2d12: Loading layer [==================================================>]  4.096kB/4.096kB

908cf8238301: Loading layer [==================================================>]  3.584kB/3.584kB

Loaded image: nginx:latest

[root@node-03 ~]#

[root@node-03 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

nginx               latest              7e4d58f0e5f3        5 days ago          133MB

[root@node-03 ~]#

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值