在Docker怎么查看镜像的元数据

简介: Docker操作 (五)

查看镜像的元数据

docker inspect --help
# 命令
docker inspect 容器id

# 测试
C:\cmder
λ docker inspect 0c7ee03d76dd   # 
[
    {
   
        "Id": "0c7ee03d76ddc6dd4c8caea4a639bcbd191309f1f6794c223bb62958f05e13cc",
        "Created": "2022-01-05T13:49:27.0383541Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "while true;do echo bruce_liu;sleep 1;done"
        ],
        "State": {
   
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 5113,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-01-05T13:49:27.6480989Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/0c7ee03d76ddc6dd4c8caea4a639bcbd191309f1f6794c223bb62958f05e13cc/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/0c7ee03d76ddc6dd4c8caea4a639bcbd191309f1f6794c223bb62958f05e13cc/hostname",
        "HostsPath": "/var/lib/docker/containers/0c7ee03d76ddc6dd4c8caea4a639bcbd191309f1f6794c223bb62958f05e13cc/hosts",
        "LogPath": "/var/lib/docker/containers/0c7ee03d76ddc6dd4c8caea4a639bcbd191309f1f6794c223bb62958f05e13cc/0c7ee03d76ddc6dd4c8caea4a639bcbd191309f1f6794c223bb62958f05e13cc-json.log",
        "Name": "/brave_cartwright",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
   
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
   
                "Type": "json-file",
                "Config": {
   }
            },
            "NetworkMode": "default",
            "PortBindings": {
   },
            "RestartPolicy": {
   
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                30,
                120
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
   
            "Data": {
   
                "LowerDir": "/var/lib/docker/overlay2/24d07c55a599d8b51e7035d22fd8d1825e132552271702bc42c1410417e22a01-init/diff:/var/lib/docker/overlay2/88853f06c6da7ba74b65019d6f86fcff4301dba97631a2cdd7ebe466cbc3cc0f/diff",
                "MergedDir": "/var/lib/docker/overlay2/24d07c55a599d8b51e7035d22fd8d1825e132552271702bc42c1410417e22a01/merged",
                "UpperDir": "/var/lib/docker/overlay2/24d07c55a599d8b51e7035d22fd8d1825e132552271702bc42c1410417e22a01/diff",
                "WorkDir": "/var/lib/docker/overlay2/24d07c55a599d8b51e7035d22fd8d1825e132552271702bc42c1410417e22a01/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
   
            "Hostname": "0c7ee03d76dd",
            "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",
                "while true;do echo bruce_liu;sleep 1;done"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
   
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "NetworkSettings": {
   
            "Bridge": "",
            "SandboxID": "325904a8305da35e3bccb874c66331dceabb2fb0917e0e5f364ec144dac6d891",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
   },
            "SandboxKey": "/var/run/docker/netns/325904a8305d",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "ca20615b2260f60d00b7a801466257e4cf180d6a9cc51ca5b7fe1a31fb5a0241",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
   
                "bridge": {
   
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "bc7d4b7e5df6399b894535936e96884d6f4fd226f10bd0118f2d8293f8df5fc6",
                    "EndpointID": "ca20615b2260f60d00b7a801466257e4cf180d6a9cc51ca5b7fe1a31fb5a0241",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

进入当前正在运行的容器

# 我们通常容器都使用后台方式运行的,需要进入容器,修改一些配置
# 命令
docker exec  -it 容器id bashShell
C:\cmder
λ docker exec -it 0c7ee03d76dd /bin/bash
[root@0c7ee03d76dd /]# pwd
/
[root@0c7ee03d76dd /]# clear
bash: clear: command not found
[root@0c7ee03d76dd /]# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

# 方式二
docker attach 容器id
docker attach --help
# 测试
C:\cmder
λ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS     NAMES
0c7ee03d76dd   centos    "/bin/sh -c 'while t…"   44 minutes ago   Up 44 minutes             brave_cartwright

C:\cmder
λ docker attach 0c7ee03d76dd
bruce_liu
bruce_liu
bruce_liu
bruce_liu
正在执行当前的代码......
# docker exec      ---------进入容器后开启一个新的终端,可以在里面操作(常用)
# docker attach    ---------进入容器正在执行的终端,不会启动新的进程!

从容器内拷贝文件到主机上

docker cp 容器id:容器内路径 目的地主机路径
docker cp 容器id:路径/文件  目的主机路径
# 进入docker容器内部
docker attach 容器id
# 在容器内执行命令 touch test.java
# 然后执行exit, 退出容器
# 将这个文件拷贝出来的到主机上
docker cp 容器id:/test.java c:\

# 拷贝是一个手动过程,未来我们使用 -v 卷的技术,可以实现

学习方式:将所有命令全部敲一遍,自己记录 笔记
小结:
image.png

attach   Attach to a running container                       # 当前shell下attach连接指定运行镜像
build      Build an image from  a Dockerfile                     # 通过Dockerfile 定制镜像
commit      Create a new image from a container changes        # 提交当前容器为新的镜像
cp       Copy files/folders from the containers filesystem to the host path       # 从容器中拷贝指定文件或者目录到宿主机
create   Create a new container                             # 创建一个新的容器, 同run ,但不启动容器
diff      Inspect changes on a container's filesystem           # 查看docker容器变化
events   Get real time events from the server                # 从docker服务获取容器实时事件
exec     Run  a command in an existing container                # 在已存在的容器上运行命令
export     Stream the contents of a container as a tar archive      # 导出容器的内容流作为一个tar,归档文件[对应import]
history     Show the history of an image                             # 展示一个镜像形成历史
images     List images                                         # 列出系统当前镜像
import   Create a new filesystem image from the contents of a tarball  # 从tar包中的内容创建一个新的文件系统映像[对应export]
info     Display system-wide information                    # 显示系统相关信息
inspect  Return low-level information on a container             # 查看容器详细信息
kill      Kill a running container                             # kill 指定的docker 容器
load     Load an image from a tar archive                    # 从一个tar包中加载一个镜像[对应save]
login     Register or Login to the docker registry server        # 注册或者登录一个docker源服务器
logout      Log out from a Docker registry server                  # 从当前docker registry退出
logs      Fetch the logs of a container                        # 输出当前容器日志信息
port      Lookup the public-facing port which is NAT-ed to PRIVATE_PORT   # 查看映射端口对应的容器内部源端口
pause     Pause all processs within a container                 # 暂停容器
ps          List containers                                    # 列出容器列表
pull      Pull an image or a repository from the docker registry server   # 从docker镜像源服务器拉取指定镜像或者镜像库
push       Push an image or a repository to the docker registry server     # 推送指定镜像或者库镜像至docker 源服务器
restart  Restart a running container                         # 重启运行的容器
rm          Remove one or more containers                        # 移除一个或者多个容器
rmi      Remove one or more images                # 移除一个或者多个镜像[无容器使用该镜像才可删除,否则删除相关容器才可继续或-f 强制删除]
run      Run a command in a new container          # 创建一个新的容器并运行一个命令
save     Save an image to a tar archive             # 保存一个镜像为一个tar包(对应load)
search       Search for an image on the Docker Hub        # 在docker hub中搜索镜像
start     Start a stopped containers              # 启动容器
stop     Stop a running containers                  # 停止容器
tag      Tag an image into a repository           # 给源中镜像打标签
unpause      Unpause a paused container               # 取消暂停容器
version   Show the docker version information        # 查看docker版本号
wait      Block until a  container stops, then print its exit code    # 截取容器停止时的退出状态值
相关文章
|
1月前
|
应用服务中间件 Linux nginx
Docker镜像-手动制作yum版nginx镜像
这篇文章介绍了如何手动制作一个基于CentOS 7.6的Docker镜像,其中包括下载指定版本的CentOS镜像,创建容器,配置阿里云软件源,安装并配置nginx,自定义nginx日志格式和web页面,最后提交镜像并基于该镜像启动新容器的详细步骤。
118 21
Docker镜像-手动制作yum版nginx镜像
|
3天前
|
搜索推荐 应用服务中间件 nginx
docker与containerd镜像获取及导出导入的区别与注意事项(报错信息:ctr: content digest sha256........ac47: not found)
docker与containerd镜像获取及导出导入的区别与注意事项(报错信息:ctr: content digest sha256........ac47: not found)
|
14天前
|
jenkins 持续交付 Docker
docker之自定义制作镜像(python程序)
docker之自定义制作镜像(python程序)
|
1月前
|
应用服务中间件 nginx Docker
Docker镜像-基于DockerFile制作编译版nginx镜像
这篇文章介绍了如何基于Dockerfile制作一个编译版的nginx镜像,并提供了详细的步骤和命令。
171 17
Docker镜像-基于DockerFile制作编译版nginx镜像
|
9天前
|
Java Docker 微服务
|
1月前
|
应用服务中间件 Linux nginx
Docker镜像管理篇
关于Docker镜像管理的教程,涵盖了Docker镜像的基本概念、管理命令以及如何制作Docker镜像等内容。
131 7
Docker镜像管理篇
|
1月前
|
应用服务中间件 Linux nginx
Docker镜像-基于DockerFile制作yum版nginx镜像
本文介绍了如何使用Dockerfile制作一个基于CentOS 7.6.1810的yum版nginx镜像,并提供了详细的步骤和命令。
77 20
|
1天前
|
Java Linux Maven
Docker镜像部署至Rancher全局配置 以xxl-job-admin为例
Docker镜像部署至Rancher全局配置 以xxl-job-admin为例
8 0
|
1天前
|
数据可视化 应用服务中间件 nginx
Docker如何连接至本地私服Harbor中 推送镜像、查看镜像、下载镜像
Docker如何连接至本地私服Harbor中 推送镜像、查看镜像、下载镜像
12 0
|
9天前
|
Docker 容器
用Docker发布自己的镜像
Docker操作 (十二)
33 0