在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    # 截取容器停止时的退出状态值
相关文章
|
8天前
|
缓存 监控 持续交付
|
4天前
|
存储 缓存 Java
Java应用瘦身记:Docker镜像从674MB优化至58MB的实践指南
【10月更文挑战第22天】 在容器化时代,Docker镜像的大小直接影响到应用的部署速度和运行效率。一个轻量级的Docker镜像可以减少存储成本、加快启动时间,并提高资源利用率。本文将分享如何将一个Java基础Docker镜像从674MB缩减到58MB的实践经验。
12 1
|
11天前
|
Docker 容器
docker:记录如何在x86架构上构造和使用arm架构的镜像
为了实现国产化适配,需将原x86平台上的Docker镜像转换为适用于ARM平台的镜像。本文介绍了如何配置Docker buildx环境,包括检查Docker版本、安装buildx插件、启用实验性功能及构建多平台镜像的具体步骤。通过这些操作,可以在x86平台上成功构建并运行ARM64镜像,实现跨平台的应用部署。
63 2
|
15天前
|
网络协议 Docker 容器
docker pull命令拉取镜像失败的解决方案
docker pull命令拉取镜像失败的解决方案
328 0
|
23天前
|
Java Docker 微服务
SpringBoot微服务打包Docker镜像
SpringBoot微服务打包Docker镜像
53 11
|
15天前
|
Go Docker Python
docker的python与go镜像的制作
docker的python与go镜像的制作
20 1
|
23天前
|
Docker 容器
用Docker发布自己的镜像
用Docker发布自己的镜像
52 9
|
24天前
|
存储 安全 Ubuntu
docker中的镜像
【10月更文挑战第1天】
37 4
|
22天前
|
缓存 安全 Linux
docker镜像管理问题
【10月更文挑战第3天】
70 1
|
24天前
|
Docker 容器
docker的导入本地镜像和导出本地镜像
本文介绍了如何使用Docker对本地镜像进行导入和导出操作,包括从本地导入`nginx.tar`镜像以及将`open-webui`镜像导出并压缩为`open-webui.tar.gz`。
48 1