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

推荐阅读