Docker | 常用命令——排錯很有幫助

眾所周知,docker 排查問題相較而言是困難的 。因此,熟知一些常用命令對我們快速的排查定位問題是非常有幫助的 。下面讓我們一起來學習一下吧
1、顯示docker的系統信息docker info
[root@xiao docker]# docker infoClient: Context:default Debug Mode: false Plugins:app: Docker App (Docker Inc., v0.9.1-beta3)buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)scan: Docker Scan (Docker Inc.)Server: Containers: 8Running: 5Paused: 0Stopped: 3 Images: 16 Server Version: 20.10.8 Storage Driver: overlay2Backing Filesystem: extfsSupports d_type: trueNative Overlay Diff: trueuserxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 1 Plugins:Volume: localNetwork: bridge host ipvlan macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc Default Runtime: runc Init Binary: docker-init containerd version: e25210fe30a0a703442421b0f60afac609f950a3 runc version: v1.0.1-0-g4144b63 init version: de40ad0 Security Options:seccompProfile: default Kernel Version: 3.10.0-1062.1.2.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 CPUs: 1 Total Memory: 1.795GiB Name: xiao ID: SR3Y:RSZT:2ZAE:M33P:O2LT:55KN:A3XY:WE7V:QXJY:7Z32:M34L:NX7N Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries:127.0.0.0/8 Registry Mirrors:https://4h8ex9ed.mirror.aliyuncs.com/ Live Restore Enabled: false[root@xiao docker]#docker version#顯示docker的版本信息docker info#顯示docker的系統信息,包括鏡像和容器的數量docker --help文檔地址: https://docs.docker.com/reference/
port# 查看映射端口對應的容器內部源端口pause# 暫停容器ps# 容器列表pull# 從docker鏡像源服務器拉取指定鏡像或者庫鏡像push# 推送指定鏡像或者庫鏡像至docker源服務器restart# 重啟運行的容器rm# 移除一個或多個容器rmi# 移除一個或多個鏡像 (無容器使用該鏡像才可刪除,否則需要刪除相關容器才可繼續或 -f 強制刪除)run# 創建一個新的容器并運行一個命令save# 保存一個鏡像為一個 tar 包【對應 load】search# 在 docker hub 中搜索鏡像start# 啟動容器stop# 停止容器tag# 給源中鏡像打標簽top# 查看容器中運行的進程信息unpause# 取消暫停容器version# 查看 docker版本號wait# 截取容器停止時的退出狀態值attach# Attach to a running container#當前shell下attach連接指定運行鏡像build# Build an image from a Dockerfile#通過Dockerfile定制鏡像commit# Create a new image from a containers changes#提交當前容器為新的鏡像cp# Copy files/folders from a container to a HOSTDIR or to STDOUT#從容器中拷貝指定文件或者目錄到宿主機中create# Create a new container#創建一個新的容器,同run 但不啟動容器diff# Inspect changes on a containers filesystem#查看docker容器變化events# Get real time events from the server#從docker服務獲取容器實時事件exec# Run a command in a running container#在已存在的容器上運行命令export# Export a containers filesystem as a tar archive#導出容器的內容流作為一個tar歸檔文件(對應import)history# Show the history of an image#展示一個鏡像形成歷史inspect# 查看容器詳細信息kill# kill 指定的容器2、鏡像命令docker images
docker imagesREPOSITORYTAGIMAGE IDCREATEDSIZEjenkins/jenkinslatestba8a0e5dc5cb4 months ago570MBnginxlatestd1a364dc548d4 months ago133MBportainer/portainerlatest580c0e4e98b06 months ago79.1MBhello-worldlatestd1165f2212346 months ago13.3kB# 解釋REPOSITORY: 鏡像倉庫源TAG: 鏡像版本信息IMAGE ID: 鏡像的IDCREATED: 鏡像的創建實際愛你SIZE: 鏡像的大小可選參數docker images -a : (--all) 列出所有鏡像 -q : (--quiet) 只顯示鏡像ID2.1、搜索鏡像docker search [xxx]
docker search mysqlNAMEDESCRIPTIONSTARSOFFICIALAUTOMATEDmysqlMySQL is a widely used, open-source relation…11470[OK]mariadbMariaDB Server is a high performing open sou…4354[OK]mysql/mysql-serverOptimized MySQL Server Docker images. Create…848[OK]perconaPercona Server is a fork of the MySQL relati…555[OK]phpmyadminphpMyAdmin - A web interface for MySQL and M…332[OK]centos/mysql-57-centos7MySQL 5.7 SQL database server91[OK]docker search mysql --filter=STARS=3000 # 搜索start數大于3000的NAMEDESCRIPTIONSTARSOFFICIALAUTOMATEDmysqlMySQL is a widely used, open-source relation…11470[OK]mariadbMariaDB Server is a high performing open sou…4354[OK]2.2、拉取鏡像hub 搜索
Docker | 常用命令——排錯很有幫助

文章插圖
docker pull 鏡像名[:tag]# egdocker pull mysqlUsing default tag: latest# 如果不寫tag, 默認就是latestlatest: Pulling from library/mysqla330b6cecb98: Pull complete# 分層下載,docker image 的核心 聯合文件系統9c8f656c32b8: Pull complete88e473c3f553: Pull complete062463ea5d2f: Pull completedaf7e3bdf4b6: Pull complete1839c0b7aac9: Pull completecf0a0cfee6d0: Pull complete1b42041bb11e: Pull complete10459d86c7e6: Pull completeb7199599d5f9: Pull complete1d6f51e17d45: Pull complete50e0789bacad: Pull completeDigest: sha256:99e0989e7e3797cfbdb8d51a19d32c8d286dd8862794d01a547651a896bcf00c# 簽名Status: Downloaded newer image for mysql:latestdocker.io/library/mysql:latest# 真實地址----docker pull mysql等價于docker pull docker.io/library/mysql:latest---# 指定tagdocker pull mysql:5.75.7: Pulling from library/mysqla330b6cecb98: Already exists# 聯合文件系統,已存在的不再重復下載9c8f656c32b8: Already exists88e473c3f553: Already exists062463ea5d2f: Already existsdaf7e3bdf4b6: Already exists1839c0b7aac9: Already existscf0a0cfee6d0: Already existsfae7a809788c: Pull complete# 下載不存在的dae5a82a61f0: Pull complete7063da9569eb: Pull complete51a9a9b4ef36: Pull completeDigest: sha256:d9b934cdf6826629f8d02ea01f28b2c4ddb1ae27c32664b14867324b3e5e1291Status: Downloaded newer image for mysql:5.7docker.io/library/mysql:5.7---#查看docker imagesREPOSITORYTAGIMAGE IDCREATEDSIZEmysql5.71d7aba9171693 weeks ago448MBmysqllatest0716d6ebcc1a3 weeks ago514MBjenkins/jenkinslatestba8a0e5dc5cb4 months ago570MBnginxlatestd1a364dc548d4 months ago133MBportainer/portainerlatest580c0e4e98b06 months ago79.1MBhello-worldlatestd1165f2212346 months ago13.3kB

推薦閱讀