Notice: Constant WP_DEBUG already defined in /var/www/html/wordpress/wp-content/plugins/changyan/sohuchangyan.php on line 12

Notice: Constant WP_DEBUG_LOG already defined in /var/www/html/wordpress/wp-content/plugins/changyan/sohuchangyan.php on line 13

Notice: Constant WP_DEBUG_DISPLAY already defined in /var/www/html/wordpress/wp-content/plugins/changyan/sohuchangyan.php on line 14
镜像是Docker运行容器的前提【zoues.com】 – zoues

LOADING

Follow me

镜像是Docker运行容器的前提【zoues.com】
六月 3, 2017|DockerPaaS

镜像是Docker运行容器的前提【zoues.com】

镜像是Docker运行容器的前提【zoues.com】

 既然镜像是Docker运行容器的前提,接下来我们从Docker Hub的仓库下载一个Centos6操作系统的镜像。

 [root@BJ-YF-docker001 ~]# docker pull docker.io/treasureboat/centos6

将镜像到本地后,就可以利用该镜像创建一个容器,在其中运行 bash 应用,如下:

#创建容器

[root@BJ-YF-docker001 ~]# docker run -t -i docker.io/treasureboat/centos6 /bin/bash

#查看容器的IP地址
[root@0f34b53fdd4d /]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe11:3/64 scope link
       valid_lft forever preferred_lft forever

#查看下载完毕的Centos6镜像的信息
[root@BJ-YF-docker001 ~]# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
dockerpool/my-lamp-app            latest              0ad7d4712ffc        26 hours ago        538.4 MB
docker.io/sebp/elk                latest              b2ead07ab3f2        2 weeks ago         1.028 GB
docker.io/webdevops/php-nginx     latest              69441b98d273        2 weeks ago         580.8 MB
docker.io/nickistre/centos-lamp   latest              b45f1e1c24ef        12 months ago       538.4 MB
docker.io/treasureboat/centos6    latest              869ead6d5987        2 years ago         465.7 MB

 

字段说明:

来自于哪个仓库,比如docker.io/treasureboat/centos6仓库。

镜像的标签信息,比如latest。

镜像的ID号(唯一)。

创建时间。

镜像大小。

其中镜像的ID信息十分重要,它唯一标识了镜像。

TAG信息用于标记来自同一个仓库的不同镜像。

 

如需获取镜像更详细的信息,则需要另外一个命令

[root@BJ-YF-docker001 ~]# docker inspect 869ead6d5987

[
    {
        “Id”: “sha256:869ead6d598793904d93b996155cae4b18bb63ee67a83ce0800ad79e71efb45e”,
        “RepoTags”: [
            “docker.io/treasureboat/centos6:latest”
        ],
        “RepoDigests”: [
            “docker.io/treasureboat/centos6@sha256:590b191c3fcd3fa2e0c0bbd9e60999ca79aaa08a9e2013a04161350c1f7928f0”
        ],
        “Parent”: “”,
        “Comment”: “”,
        “Created”: “2015-01-25T19:05:20.669252821Z”,
        “Container”: “20e519f45c919256658dad4ec87c0c128f3aa17c1b75cdb338cd14af2c1098ed”,
        “ContainerConfig”: {
            “Hostname”: “28b0332b0f96”,
            “Domainname”: “”,
            “User”: “”,
            “AttachStdin”: false,
            “AttachStdout”: false,
            “AttachStderr”: false,
            “Tty”: false,
            “OpenStdin”: false,
            “StdinOnce”: false,
            “Env”: [
                “PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
            ],
            “Cmd”: [
                “/bin/sh”,
                “-c”,
                “yum install -y rsyslog”
            ],
            “Image”: “eb2e96a631806f32d6f10722b3e42802fc12c6ff75464b69c3ab11a9ed4e2d42”,
            “Volumes”: null,
            “WorkingDir”: “”,
            “Entrypoint”: null,
            “OnBuild”: [],
            “Labels”: null
        },
        “DockerVersion”: “1.3.3”,
        “Author”: “treasureboat /u003coffice@treasureboat.org/u003e”,
        “Config”: {
            “Hostname”: “28b0332b0f96”,
            “Domainname”: “”,
            “User”: “”,
            “AttachStdin”: false,
            “AttachStdout”: false,
            “AttachStderr”: false,
            “Tty”: false,
            “OpenStdin”: false,
            “StdinOnce”: false,
            “Env”: [
                “PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”
            ],
            “Cmd”: null,
            “Image”: “eb2e96a631806f32d6f10722b3e42802fc12c6ff75464b69c3ab11a9ed4e2d42”,
            “Volumes”: null,
            “WorkingDir”: “”,
            “Entrypoint”: null,
            “OnBuild”: [],
            “Labels”: null
        },
        “Architecture”: “amd64”,
        “Os”: “linux”,
        “Size”: 465655928,
        “VirtualSize”: 465655928,
        “GraphDriver”: {
            “Name”: “devicemapper”,
            “Data”: {
                “DeviceId”: “32”,
                “DeviceName”: “docker-8:2-261879-4e15f402e20b83c116af61ca1a2b98da1f7096270596d15cbab0aaf1915a456f”,
                “DeviceSize”: “10737418240”
            }
        },
        “RootFS”: {
            “Type”: “layers”,
            “Layers”: [
                “sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef”,
                “sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef”,
                “sha256:946cd90762dc6d1e0926b132ef57389b29e5760b49922b12fe9b089b0168ebe5”,
                “sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef”,
                “sha256:ab2af1db7d1d335c6d01dcb021160fc2c22a48ae86d98068e857321897432b8d”,
                “sha256:adea6e4589ef09bdec3cda21b6dc2e48fb6aa600d7e90d6161009805a958af19”,
                “sha256:e289d1ab3cd7c0db690adc03fe923affff0b7b0639723ba162bf669681dfa176”,
                “sha256:5c4a4f8baedbdd8752076a68e0e2701434e72619da3812a91d66869feb29a26c”,
                “sha256:f3d81bd9a054bd161eeb1096599a31b4f259c40c0329ae246922dac8cc54e5c0”
            ]
        }
    }
]

使用-f参数我们可以获取指定项内容,如,获取镜像的Architecture信息:

[root@BJ-YF-docker001 ~]# docker inspect -f {{“.Architecture”}} 869ead6d5987

amd64

#查找镜像

[root@BJ-YF-docker001 ~]# docker search centos

#删除指定镜像

[root@BJ-YF-docker001 ~]# docker  rmi  869ead6d5987

注意,当有该镜像创建的容器存在时,镜像文件默认是无法被删除的,

 

更多技能,敬请关注“老薛Linux大讲堂”

 

镜像是Docker运行容器的前提

no comments
Share