本文共 3430 字,大约阅读时间需要 11 分钟。
docker 基础命令
[root@sys ~]# docker info #docker 宿主机基本信息
Containers: 8Images: 18Storage Driver: devicemapperPool Name: docker-8:3-918403-poolPool Blocksize: 65.54 kBBacking Filesystem: extfsData file: /dev/loop0Metadata file: /dev/loop1Data Space Used: 804.9 MBData Space Total: 107.4 GBData Space Available: 18.16 GBMetadata Space Used: 1.716 MBMetadata Space Total: 2.147 GBMetadata Space Available: 2.146 GBUdev Sync Supported: trueDeferred Removal Enabled: falseData loop file: /var/lib/docker/devicemapper/devicemapper/dataMetadata loop file: /var/lib/docker/devicemapper/devicemapper/metadataLibrary Version: 1.02.117-RHEL6 (2016-04-01)Execution Driver: native-0.2Logging Driver: json-fileKernel Version: 2.6.32-642.el6.x86_64Operating System:CPUs: 1Total Memory: 980.6 MiBName: sys.kanfanews.comID: HFOV:3GDL:KISC:YJPU:PONC:7JPU:NNTV:M675:G25U:KAQZ:U2CP:CEWOYou have new mail in /var/spool/mail/root
查看docker 版本
[root@sys ~]# docker versionClient version: 1.7.1Client API version: 1.19Go version (client): go1.4.2Git commit (client): 786b29d/1.7.1OS/Arch (client): linux/amd64Server version: 1.7.1Server API version: 1.19Go version (server): go1.4.2Git commit (server): 786b29d/1.7.1OS/Arch (server): linux/amd64
[root@sys ~]# docker images #列出机器上的镜像(images)
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEnginx latest 70db66768c22 4 weeks ago 108.4 MBnginx 1.10.3 5cd84ba04b60 8 months ago 181.5 MB
查看信息
查看本地镜像
[root@sys ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEnginx latest e641e400bfe5 11 days ago 108.5 MBnginx 1.10.3 5cd84ba04b60 8 months ago 181.5 MB
查看当前运行的容器
[root@sys ~]# docker ps
\CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES6fe819407ae2 nginx "nginx -g 'daemon of About an hour ago Up 16 minutes 0.0.0.0:80->80/tcp clever_yonath查看所有的容器
[root@sys ~]\# docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES6fe819407ae2 nginx "nginx -g 'daemon of About an hour ago Up 16 minutes 0.0.0.0:80->80/tcp clever_yonath 3ad7725a72f3 nginx "nginx -g 'daemon of About an hour ago Exited (0) About an hour ago hungry_mcclintock
动态查看容器日志
[root@sys ~]\# docker logs -f 6fe819407ae2192.168.24.1 - - [04/Dec/2017:07:48:41 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36"
单个容器操作
[root@sys ~]#docker start 3ad7725a72f3 #启动某个容器[root@sys ~]#docker stop 3ad7725a72f3 #关闭某个容器
删除操作
[root@sys ~]# docker rmi nginx #删除镜像[root@sys ~]# docker rm 08a40f59bf14 #删除容器
批量容器操作
[root@sys ~]#docker kill $(docker ps -a -q) #杀死所有正在运行的容器[root@sys ~]#docker rm $(docker ps -a -q) #删除所有已经停止的容器[root@sys ~]#docker rmi $(docker images -q)#删除所有镜像[root@sys ~]#docker rmi $(docker images -q -f dangling=true) #删除所有未打 dangling 标签的镜像[root@sys ~]#docker rmi --force $(docker images | grep doss-api | awk '{print $3}') #强制删除镜像名称中包含“doss-api”的镜像
进入容器
[root@caosm03 ~]# docker exec -it 6fe819407ae2 /bin/bash
转载于:https://blog.51cto.com/innocence/2047280