文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

docker如何查看容器启动命令(已运行的容器)

2023-02-22 12:00

关注

eg:

docker ps 查看正在运行的容器:

通过docker ps命令

该命令主要是为了详细展示查看运行时的command参数

docker ps -a --no-trunc | grep container_name   # 通过docker --no-trunc参数来详细展示容器运行命令

通过docker inspect命令

使用docker inspect,但是docker inspect打印的是json文件,需要挑选字段查看,容器的参数信息都能从json文件中解析出来。

1,在容器外部,物理机上,可以用下面命令

docker inspect <container_name>   # 可以是container_name或者container_id

eg:

[root@128 ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
547880f43cf1   mysql:8.0.31   "docker-entrypoint.s…"   15 minutes ago   Up 15 minutes   33060/tcp, 0.0.0.0:3301->3306/tcp, :::3301->3306/tcp   mysql-8.0.31
e02f22dc442c   mysql:5.7      "docker-entrypoint.s…"   25 hours ago     Up 18 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@128 ~]# docker ps -a --no-trunc | grep 547880f43cf1
547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232   mysql:8.0.31          "docker-entrypoint.sh mysqld"                          15 minutes ago   Up 15 minutes                 33060/tcp, 0.0.0.0:3301->3306/tcp, :::3301->3306/tcp   mysql-8.0.31
[root@128 ~]# docker inspect 547880f43cf1
[
    {
        "Id": "547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232",
        "Created": "2022-12-07T10:13:46.80942044Z",
        "Path": "docker-entrypoint.sh",
        "Args": [
            "mysqld"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 5469,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2022-12-07T10:13:47.159621124Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:a3a2968869cf080dbbd2adaac9e4075cc358b50a1451ff5e2b9ae90551a4735f",
        "ResolvConfPath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/hostname",
        "HostsPath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/hosts",
        "LogPath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232-json.log",
        "Name": "/mysql-8.0.31",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/mydata/mysql-8.0.31/log:/var/log/mysql",
                "/mydata/mysql-8.0.31/data:/var/lib/mysql"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "3306/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "3301"
                    }
                ]
            },
            "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": [
                0,
                0
            ],
            "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/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1-init/diff:/var/lib/docker/overlay2/e6ce4810d05ed0bdca975287151d5edcb8f5b4e3472fba848ecbd0858a83c27d/diff:/var/lib/docker/overlay2/0bd4abf22bc8fd1840c48d50034d525576608654eac3696820bdecca885869e1/diff:/var/lib/docker/overlay2/aa9ffa3d8ca28910870afed61cbb7a8b5954b633b6c51ddec94b33f45fd7c69a/diff:/var/lib/docker/overlay2/7832e98417573f093c97491e70941e1a09e9a6e4e49b4407644cc367fdbeb37e/diff:/var/lib/docker/overlay2/74b73e21fc743a650a4064f4e771fd65aca511cf433aee93cc6eef2f3a91d787/diff:/var/lib/docker/overlay2/0df122c8a1629d74c09d97e489932b0812da34d28734118287934acbf3e8e985/diff:/var/lib/docker/overlay2/6f48c0c0c5bb4f2d96900b9eb4d20409a066a9bf3c104171e5dd33f28dbe6301/diff:/var/lib/docker/overlay2/37869951120d01076a5bc57e0c04c8f466a0b0b37e06357653b27b2fc9638a1d/diff:/var/lib/docker/overlay2/c2414c698ebdc9f0bacedf53387c75aa6cb000720ff019d989e4daa9d9c0929f/diff:/var/lib/docker/overlay2/099e69b07f239a7747f754a2598aec804655f5d6d7beb9ffb85932c490ec13d1/diff:/var/lib/docker/overlay2/9be3057383e74825462c49286ffa30853fb87f6d975ad40459e12972538ce21c/diff",
                "MergedDir": "/var/lib/docker/overlay2/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1/merged",
                "UpperDir": "/var/lib/docker/overlay2/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1/diff",
                "WorkDir": "/var/lib/docker/overlay2/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/mydata/mysql-8.0.31/log",
                "Destination": "/var/log/mysql",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/mydata/mysql-8.0.31/data",
                "Destination": "/var/lib/mysql",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "547880f43cf1",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3306/tcp": {},
                "33060/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "MYSQL_ROOT_PASSWORD=123456",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "GOSU_VERSION=1.14",
                "MYSQL_MAJOR=8.0",
                "MYSQL_VERSION=8.0.31-1.el8",
                "MYSQL_SHELL_VERSION=8.0.31-1.el8"
            ],
            "Cmd": [
                "mysqld"
            ],
            "Image": "mysql:8.0.31",
            "Volumes": {
                "/var/lib/mysql": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "f82246141707b2ab4578ce193cdf42b9dd82fef9d8ca805c4b07b6af90867ffc",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "3306/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "3301"
                    },
                    {
                        "HostIp": "::",
                        "HostPort": "3301"
                    }
                ],
                "33060/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/f82246141707",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "386a6348d0fd2e9119e7d427ed2df21bf03f4a88c485b50cf142d6c0b0f08f83",
            "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": "65f89f72b915b6ae63526860f40f2e701bfcc1c689301d757230f7a522379d35",
                    "EndpointID": "386a6348d0fd2e9119e7d427ed2df21bf03f4a88c485b50cf142d6c0b0f08f83",
                    "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
                }
            }
        }
    }
]

如上所示,这个是我这547880f43cf1 容器的详细信息

然后可以定制化输出上面的信息:显示上面内容的某一部分信息

docker inspect --format='{{.NetworkSettings.Networks.bridge.IPAddress}}' <container_name>      # format是go语言的template,还有其他的用法
docker inspect --format='{{.Mounts}}' <container_name>   
docker inspect --format='{{.HostConfig.Binds}}' <container_name>
docker inspect --format='{{.HostConfig.PortBindings}}' <container_name>

eg: 还可以将上面的修改为别的内容,我这边关注file和port两个

[root@128 ~]# docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
547880f43cf1   mysql:8.0.31   "docker-entrypoint.s…"   18 minutes ago   Up 18 minutes   33060/tcp, 0.0.0.0:3301->3306/tcp, :::3301->3306/tcp   mysql-8.0.31
e02f22dc442c   mysql:5.7      "docker-entrypoint.s…"   25 hours ago     Up 22 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@128 ~]# docker inspect --format='{{.Mounts}}' 547880f43cf1
[{bind  /mydata/mysql-8.0.31/log /var/log/mysql   true rprivate} {bind  /mydata/mysql-8.0.31/data /var/lib/mysql   true rprivate}]
[root@128 ~]# docker inspect --format='{{.NetworkSettings.Networks.bridge.IPAddress}}' 547880f43cf1
172.17.0.2
[root@128 ~]# docker inspect --format='{{.HostConfig.Binds}}' 547880f43cf1
[/mydata/mysql-8.0.31/log:/var/log/mysql /mydata/mysql-8.0.31/data:/var/lib/mysql]
[root@128 ~]# docker inspect --format='{{.HostConfig.PortBindings}}' 547880f43cf1
map[3306/tcp:[{ 3301}]]
[root@128 ~]#

总结

到此这篇关于docker如何查看容器启动命令的文章就介绍到这了,更多相关docker查看容器启动命令内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-服务器
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯