docker详解
参考:https://docs.docker.com/engine/reference/commandline/inspect/
数据源:
数据源: [root@host-10-0-101-156 ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 056ee68c3788 rayosx:2.0.1 "/bin/bash" 29 hours ago Up 28 hours 0.0.0.0:5901->5900/tcp stupefied_murdock f21025fccdd9 rayosx:2.0.1 "/bin/bash" 2 weeks ago Up 44 hours 0.0.0.0:5906->5900/tcp romantic_bell ff2dacef1188 rayosx:2.0.1 "/bin/bash" 2 weeks ago Up 44 hours 0.0.0.0:5907->5900/tcp vibrant_hawking f0831061479f rayosx:2.0.1 "/bin/bash" 2 weeks ago Up 44 hours 0.0.0.0:5908->5900/tcp
用法:
1、查找端口
[root@host-10-0-101-156 ~]# docker inspect -f='{{range $conf := .NetworkSettings.Ports}}{{(index $conf 0).HostPort}} {{end}}' 056ee68c3788 5901
2、查找端口映射
[root@host-10-0-101-156 ~]# docker inspect -f='{{range $p, $conf := .NetworkSettings.Ports}}{{$p}} -> {{(index $conf 0).HostPort}} {{end}}' 056ee68c3788 5900/tcp -> 5901
3、启带端口映射的docker
[root@docker docker]# docker run -it -p 5907:5900 -v /opt:/gxycloud -v /sys/fs/cgroup:/sys/fs/cgroup --privileged --shm-size=1g fedora:25 /bin/bash
4、停止docker
[root@docker test]# docker stop 5219ceb7e061
5219ceb7e061
5、删除docker前要先停止
[root@docker test]# docker rm 5219ceb7e061
5219ceb7e061
6、docker帮助
[root@docker test]# docker --help Usage: docker COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/root/.docker") -D, --debug Enable debug mode --help Print usage -H, --host list Daemon socket(s) to connect to -l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem") --tlskey string Path to TLS key file (default "/root/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: config Manage Docker configs container Manage containers image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker volume Manage volumes Commands: attach Attach local standard input, output, and error streams to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes to files or directories on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit c
#查看usb设备
[root@docker ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 1 14.3G 0 disk └─sdb1 8:17 1 14.3G 0 part sr0 11:0 1 1024M 0 rom sdc 8:32 1 7.2G 0 disk ├─sdc2 8:34 1 5.2M 0 part └─sdc1 8:33 1 1.9G 0 part sda 8:0 0 100G 0 disk ├─sda2 8:2 0 99G 0 part │ ├─fedora-swap 253:1 0 4G 0 lvm [SWAP] │ └─fedora-root 253:0 0 95G 0 lvm / └─sda1 8:1 0 1G 0 part /boot
#查看usb对应bus
[root@docker ~]# lsusb -t
/: Bus 63.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 62.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 61.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 60.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 59.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 58.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 57.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 56.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 55.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 54.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 53.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 52.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 51.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 50.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 49.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 48.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 47.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 46.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 45.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 44.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 43.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 42.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 41.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 40.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 39.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 38.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 37.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 36.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 35.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 34.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 33.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 32.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 31.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 30.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 29.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 28.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 27.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 26.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 25.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 24.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 23.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 22.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 21.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 20.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 19.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 18.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 17.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 16.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 15.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 14.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 13.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 12.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 11.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 10.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 09.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 08.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 07.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 06.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
|__ Port 5: Dev 3, If 0, Class=Mass Storage, Driver=usb-storage, 480M
|__ Port 6: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-pci/6p, 480M
#获取所有docker
[root@docker ~]# cat all_docker_info.py import os def get_all_docker(): docker_exist = os.popen('docker ps -a').read() print(docker_exist) if __name__ == '__main__': get_all_docker()
执行结果:
[root@docker ~]# python3 all_docker_info.py CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f76757552734 fedora:25 "/bin/bash" 9 minutes ago Exited (0) 9 minutes ago hopeful_cray 985121ddbe06 fedora:25 "/bin/bash" 10 minutes ago Up 9 minutes 0.0.0.0:5903->5900/tcp boring_franklin 0e011fc3a878 fedora:25 "/bin/bash" 29 hours ago Up 29 hours 0.0.0.0:5902->5900/tcp infallible_galileo