其他分享
首页 > 其他分享> > 7、常用其它命令

7、常用其它命令

作者:互联网

常用其它命令

后台启动容器

# docker  run -d  镜像名
#问题 docker ps,发现centos停止了
#常见的坑:docker容器使用后台运行,就必须要有一个前台进程,docker发现没有应用,就会自动停止

查看日志命令

# docker logs

查看容器进程信息

# docker top 容器ID
[root@iZ2zee7khd9swlno7xr3hsZ ~]# docker top 979510c756a5
UID     PID    PPID    C     STIME      TTY                 TIME                CMD
root   22334   22314   0     13:02      pts/0               00:00:00            /bin/bash

查看镜像元数据

# docker inspect 容器ID



[root@iZ2zee7khd9swlno7xr3hsZ ~]# docker inspect 979510c756a5
[
    {
        "Id": "979510c756a56364d0478ece4719f3817ee21d56b336f23ee9edd265ee5d9c3d",
        "Created": "2021-08-30T04:41:21.362563633Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 22334,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-08-30T05:02:52.952364915Z",
            "FinishedAt": "2021-08-30T04:42:18.819139088Z"
        },
        "Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
        "ResolvConfPath": "/var/lib/docker/containers/979510c756a56364d0478ece4719f3817ee21d56b336f23ee9edd265ee5d9c3d/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/979510c756a56364d0478ece4719f3817ee21d56b336f23ee9edd265ee5d9c3d/hostname",
        "HostsPath": "/var/lib/docker/containers/979510c756a56364d0478ece4719f3817ee21d56b336f23ee9edd265ee5d9c3d/hosts",
        "LogPath": "/var/lib/docker/containers/979510c756a56364d0478ece4719f3817ee21d56b336f23ee9edd265ee5d9c3d/979510c756a56364d0478ece4719f3817ee21d56b336f23ee9edd265ee5d9c3d-json.log",
        "Name": "/relaxed_curie",
        "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": [
                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/abc8279ec815367a76592e9784eec5022ce83da617afe385acf93ff3ad41044c-init/diff:/var/lib/docker/overlay2/78462af537e76cc80b9e640aaa43993b8faa6324264834a7bcbbe62b3e621967/diff",
                "MergedDir": "/var/lib/docker/overlay2/abc8279ec815367a76592e9784eec5022ce83da617afe385acf93ff3ad41044c/merged",
                "UpperDir": "/var/lib/docker/overlay2/abc8279ec815367a76592e9784eec5022ce83da617afe385acf93ff3ad41044c/diff",
                "WorkDir": "/var/lib/docker/overlay2/abc8279ec815367a76592e9784eec5022ce83da617afe385acf93ff3ad41044c/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "979510c756a5",
            "Domainname": "",
            "User": "",
            "AttachStdin": true,
            "AttachStdout": true,
            "AttachStderr": true,
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": true,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20201204",
                "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": "7927be53303efaef3f2f4a4eaf088db6727ab8e01f88c144b10ffc761d383384",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/7927be53303e",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "bfbc94fd3954594b4f85b6828451e777e9d39b5a9a400e54c677966e6fe6ab36",
            "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": "be033bd6a203394014c003890bb4abcf9180545acc01a010787cdf24f602b701",
                    "EndpointID": "bfbc94fd3954594b4f85b6828451e777e9d39b5a9a400e54c677966e6fe6ab36",
                    "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 

[root@iZ2zee7khd9swlno7xr3hsZ ~]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS         PORTS     NAMES
979510c756a5   centos    "/bin/bash"   30 minutes ago   Up 9 minutes             relaxed_curie
[root@iZ2zee7khd9swlno7xr3hsZ ~]# docker exec -it 979510c756a5 /bin/bash
[root@979510c756a5 /]# 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 exec # 进入容器开启一个新的终端
docker attach # 进入容器正在执行的终端

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

# docker cp  容器id:目录  目标目录

标签:常用,其它,false,lib,命令,var,docker,null,proc
来源: https://blog.csdn.net/weixin_43691960/article/details/122360797