IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> docker常用命令 -> 正文阅读

[系统运维]docker常用命令

docker官方命令参考文档: https://docs.docker.com/reference

查看docker版本

[root@VM-12-11-centos etc]# docker version
Client: Docker Engine - Community
 Version:           20.10.11
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        dea9396
 Built:             Thu Nov 18 00:38:53 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.11
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       847da18
  Built:            Thu Nov 18 00:37:17 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

查看docker详细信息

[root@VM-12-11-centos etc]# docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 1			#镜像数
 Server Version: 20.10.11
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: 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: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 3.10.0-1160.45.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.7GiB
 Name: VM-12-11-centos
 ID: W2KJ:NNJT:CZNM:FRCC:ZWZI:MHEP:TIO3:VDDW:3STD:PNT5:OIL7:DQVK
 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://3fduez2n.mirror.aliyuncs.com/
 Live Restore Enabled: false

镜像命令

查看所有本地镜像——镜像命令

Options:
  -a, --all             # 显示所有的镜像(默认隐藏中间镜像)
      --digests         # 显示摘要
  -f, --filter filter   # 根据所提供的条件过滤输出
      --format string   # 使用Go模板美化打印镜像
      --no-trunc        # 不截断输出
  -q, --quiet           # 只显示镜像id

[root@VM-12-11-centos etc]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB

# 组合操作
[root@VM-12-11-centos etc]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
mysql         latest    bbf6571db497   12 days ago    516MB
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB

#查出所有镜像的Id
[root@VM-12-11-centos etc]# docker images -aq
bbf6571db497
feb5d9fea6a5

搜索镜像——镜像命令

  • 可以去官网进行搜索,有更明细的信息可以进行查看
  • 没有注册的可以先去官网注册, 注册教程:docker 镜像注册【图文教程】
  • docker镜像官网:https://hub.docker.com
[root@VM-12-11-centos etc]# docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   11803     [OK]
mariadb                           MariaDB Server is a high performing open sou…   4492      [OK]
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   885                  [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   92
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. Cr…   89
centurylink/mysql                 Image containing mysql. Optimized to be link…   59                   [OK]
databack/mysql-backup             Back up mysql databases to... anywhere!         54
prom/mysqld-exporter                                                              44                   [OK]
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com/r…   41                   [OK]
tutum/mysql                       Base docker image to run a MySQL database se…   35
linuxserver/mysql                 A Mysql container, brought to you by LinuxSe…   34
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic backup…   31                   [OK]
mysql/mysql-router                MySQL Router provides transparent routing be…   23
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   21
arey/mysql-client                 Run a MySQL client from a docker container      19                   [OK]
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron tas…   17                   [OK]
genschsa/mysql-employees          MySQL Employee Sample Database                  8                    [OK]
yloeffler/mysql-backup            This image runs mysqldump to backup data usi…   7                    [OK]
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 image…   6
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                3                    [OK]
idoall/mysql                      MySQL is a widely used, open-source relation…   3                    [OK]
devilbox/mysql                    Retagged MySQL, MariaDB and PerconaDB offici…   3
jelastic/mysql                    An image of the MySQL database server mainta…   2
centos/mysql-80-centos7           MySQL 8.0 SQL database server                   2
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Curl…   1                    [OK]

下载镜像——镜像命令

[root@VM-12-11-centos etc]# docker pull mysql [:TAG]
Using default tag: latest		# 如果不写,默认最新版本
latest: Pulling from library/mysql
ffbb094f4f9e: Pull complete		# 分层下载,docker核心
df186527fc46: Pull complete
fa362a6aa7bd: Pull complete
5af7cb1a200e: Pull complete
949da226cc6d: Pull complete
bce007079ee9: Pull complete
eab9f076e5a3: Pull complete
8a57a7529e8d: Pull complete
b1ccc6ed6fc7: Pull complete
b4af75e64169: Pull complete
3aed6a9cd681: Pull complete
23390142f76f: Pull complete
Digest: sha256:ff9a288d1ecf4397967989b5d1ec269f7d9042a46fc8bc2c3ae35458c1a26727	#签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest	# 真实地址

## 再次下载一个镜像
[root@VM-12-11-centos etc]# docker pull mysql:5.7
5.7: Pulling from library/mysql
ffbb094f4f9e: Already exists #上一个镜像存在的层级就不再下载,公用一个层级
df186527fc46: Already exists
fa362a6aa7bd: Already exists
5af7cb1a200e: Already exists
949da226cc6d: Already exists
bce007079ee9: Already exists
eab9f076e5a3: Already exists
c7b24c3f27af: Pull complete #下载不同的层级
6fc26ff6705a: Pull complete
bec5cdb5e7f7: Pull complete
6c1cb25f7525: Pull complete
Digest: sha256:d1cc87a3bd5dc07defc837bc9084f748a130606ff41923f46dec1986e0dc828d #签名
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

删除镜像——镜像操作

# 查看当前存在的镜像
[root@VM-12-11-centos etc]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
mysql         5.7       738e7101490b   12 days ago    448MB
mysql         latest    bbf6571db497   12 days ago    516MB
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB

# 根据镜像Id删除镜像
[root@VM-12-11-centos etc]# docker rmi 738e7101490b
Untagged: mysql:5.7
Untagged: mysql@sha256:d1cc87a3bd5dc07defc837bc9084f748a130606ff41923f46dec1986e0dc828d
Deleted: sha256:738e7101490b45decf606211a5437ed87aa6a82f1ff03c354564bf9375ce20f9
Deleted: sha256:addad8cfeac97b96eb6652a576269346ac96def9a6709ed2388e24fff4345837
Deleted: sha256:e288c3439a7e2f423f50bf22979a759371c51a70bbbaa450993c336978460b1a
Deleted: sha256:33ece15accaa3bb20e3dee84e2e4501469b917c3abba3d5475cd1fec8bb3e82c
Deleted: sha256:6b15390bceeca8424d82e75f5c9aca5eb4693f96849d6382168a99747877693d

# 查看镜像已经被删除
[root@VM-12-11-centos etc]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
mysql         latest    bbf6571db497   12 days ago    516MB
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB

#根据所有的镜像Id删除所有镜像
[root@VM-12-11-centos etc]# docker rmi -f $(docker images -aq)

容器命令

说明:有了镜像之后才可以创建容器,Linux,下载一个Centos镜像测试学习

新建容器并启动

[root@VM-12-11-centos etc]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

docker启动命令

[root@VM-12-11-centos etc]# docker run --help
名称,简写默认描述
--add-host添加自定义主机到 IP 映射 (host:ip)
--attach , -a附加到 STDIN、STDOUT 或 STDERR
--blkio-weightBlock IO(相对权重),10到1000之间,或者0禁用(默认0)
--blkio-weight-device块IO权重(相对设备权重)
--cap-add添加 Linux 功能
--cap-drop删除 Linux 功能
--cgroup-parent容器的可选父 cgroup
--cgroupns要使用的Cgroup命名空间(主机
’host’:运行Docker主机cgroup命名空间中的容器
’private’:在容器自己的私有cgroup命名空间中运行容器
使用cgroup命名空间
--cidfile将容器 ID 写入文件
--cpu-countCPU 计数(仅限 Windows)
--cpu-percentCPU 百分比(仅限 Windows)
--cpu-period限制 CPU CFS(完全公平调度程序)周期
--cpu-quota限制 CPU CFS(完全公平调度程序)配额
--cpu-rt-periodAPI 1.25+ 以微秒为单位限制 CPU 实时周期
--cpu-rt-runtimeAPI 1.25+ 以微秒为单位限制 CPU 实时运行时间
--cpu-shares , -cCPU份额(相对权重)
--cpusAPI 1.25+ CPU数量
--cpuset-cpus允许执行的 CPU (0-3, 0,1)
--cpuset-mems允许执行的 MEMs (0-3, 0,1)
--detach , -d在后台运行容器并打印容器 ID
--detach-keys覆盖用于分离容器的键序列
--device将主机设备添加到容器
--device-cgroup-rule向 cgroup 允许的设备列表添加规则
--device-read-bps限制设备的读取速率(每秒字节数)
--device-read-iops限制设备的读取速率(每秒 IO)
--device-write-bps限制设备的写入速率(每秒字节数)
--device-write-iops限制设备的写入速率(每秒 IO)
--disable-content-trusttrue跳过图像验证
--dns设置自定义 DNS 服务器
--dns-opt设置 DNS 选项
--dns-option设置 DNS 选项
--dns-search设置自定义 DNS 搜索域
--domainname容器NIS域名
--entrypoint覆盖图像的默认 ENTRYPOINT
--env , -e设置环境变量
--env-file读入环境变量文件
--expose公开一个端口或一系列端口
--gpusAPI 1.40+ 要添加到容器中的 GPU 设备(‘all’ 以传递所有 GPU)
--group-add添加要加入的其他组
--health-cmd运行以检查健康状况的命令
--health-interval运行检查之间的时间(ms|s|m|h)(默认为 0s)
--health-retries报告不健康需要连续失败
--health-start-periodAPI 1.29+ 在开始健康重试倒计时(ms|s|m|h)之前容器初始化的开始时间(默认为 0s)
--health-timeout允许运行一次检查的最长时间(ms|s|m|h)(默认为 0s)
--help打印使用
--hostname , -h容器主机名
--initAPI 1.25+ 在容器内运行一个 init 来转发信号和收获进程
--interactive , -i即使未连接,也要保持 STDIN 打开
--io-maxbandwidth系统驱动器的最大 IO 带宽限制(仅限 Windows)
--io-maxiops系统驱动器的最大 IOps 限制(仅限 Windows)
--ipIPv4 地址(例如 172.30.100.104)
--ip6IPv6 地址(例如,2001:db8::33)
--ipc使用IPC模式
--isolation容器隔离技术
--kernel-memory内核内存限制
--label , -l在容器上设置元数据
--label-file读入一行分隔的标签文件
--link添加到另一个容器的链接
--link-local-ip容器 IPv4/IPv6 链路本地地址
--log-driver容器的日志驱动程序
--log-opt日志驱动程序选项
--mac-address容器 MAC 地址(例如,92:d0:c6:0a:29:33)
--memory , -m内存限制
--memory-reservation内存软限制
--memory-swap交换限制等于内存加交换:“-1”启用无限交换
--memory-swappiness-1调整容器内存交换(0 到 100)
--mount将文件系统挂载附加到容器
--name为容器指定名称
--net将容器连接到网络
--net-alias为容器添加网络范围的别名
--network将容器连接到网络
--network-alias为容器添加网络范围的别名
--no-healthcheck禁用任何容器指定的 HEALTHCHECK
--oom-kill-disable禁用 OOM 杀手
--oom-score-adj调整主机的 OOM 首选项(-1000 到 1000)
--pid要使用的 PID 命名空间
--pids-limit调整容器 pids 限制(设置 -1 表示无限制)
--platformAPI 1.32+ 如果服务器支持多平台,则设置平台
--privileged授予此容器扩展权限
--publish , -p将容器的端口发布到主机
--publish-all , -P将所有暴露的端口发布到随机端口
--pullmissing运行前拉取镜像(“总是”|“缺失”|“从不”)
--read-only将容器的根文件系统挂载为只读
--restartno容器退出时应用的重启策略
--rm退出时自动移除容器
--runtime用于此容器的运行时
--security-opt安全选项
--shm-size/dev/shm 的大小
--sig-proxytrue代理接收到进程的信号
--stop-signalSIGTERM停止容器的信号
--stop-timeoutAPI 1.25+ 停止容器的超时(以秒为单位)
--storage-opt容器的存储驱动程序选项
--sysctlsysctl 选项
--tmpfs挂载一个 tmpfs 目录
--tty , -t分配一个伪 TTY
--ulimit超限选项
--user , -u用户名或 UID(格式:<name|uid>[:<group|gid>])
--userns要使用的用户命名空间
--uts要使用的 UTS 命名空间
--volume , -v绑定挂载卷
--volume-driver容器的可选卷驱动程序
--volumes-from从指定的容器挂载卷
--workdir , -w容器内的工作目录

docker run 常用的命令

[root@VM-12-11-centos etc]# docker run [参数] images

#常用参数说明
--name	#容器名字, Tomcat1、Tomcat2……,用来区分容器
-d		#后台运行
-it		#使用交互的方式运行,进入容器内部进行查看内容
-P		#指定容器端口	-p:8080:8080
	-P ip:主机端口:容器端口
	-P 容器端口
	容器端口(直接写端口, 不使用-P标识)
-p		#大小写问题,随机指定端口

启动并进入容器

#查看当前存在的容器
[root@VM-12-11-centos etc]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
mysql         latest    bbf6571db497   12 days ago    516MB
hello-world   latest    feb5d9fea6a5   2 months ago   13.3kB
centos        latest    5d0da3dc9764   2 months ago   231MB

# 启动并进入交互式容器运行
[root@VM-12-11-centos etc]# docker run -it centos /bin/bash

#对比前面标识,已经进入容器内部操作, 退出命令【同时结束容器运行】
		# 退出容器,不结束容器运行  Ctrl + P + Q
[root@4f8480af2cb9 /]#  exit
exit

# 退回到原本的环境
[root@VM-12-11-centos etc]#

查看所有运行中的容器

#查看当前运行的容器
[root@VM-12-11-centos /]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

# 查看所有运行的容器 + 历史运行过的容器
[root@VM-12-11-centos /]# docker ps -a
CONTAINER ID   IMAGE         COMMAND       CREATED         STATUS                       PORTS     NAMES
4f8480af2cb9   centos        "/bin/bash"   4 minutes ago   Exited (130) 2 minutes ago             reverent_morse
254da3bb3c70   hello-world   "/hello"      25 hours ago    Exited (0) 25 hours ago                inspiring_elbakyan

退出容器

退出容器并结束容器运行

[root@VM-12-11-centos etc]# docker run -it centos /bin/bash
[root@4f8480af2cb9 /]#  exit
exit
[root@VM-12-11-centos etc]#

退出容器并在后台运行 ——快速按 Ctrl + P + Q

[root@VM-12-11-centos /]# docker run -it centos /bin/bash
[root@9d0cf7e6ea19 /]# 
[root@VM-12-11-centos /]# docker ps -a
CONTAINER ID   IMAGE         COMMAND       CREATED          STATUS                        PORTS     NAMES
9d0cf7e6ea19   centos        "/bin/bash"   4 minutes ago    Up 4 minutes                            youthful_hermann
4f8480af2cb9   centos        "/bin/bash"   14 minutes ago   Exited (130) 11 minutes ago             reverent_morse
254da3bb3c70   hello-world   "/hello"      25 hours ago     Exited (0) 25 hours ago                 inspiring_elbakyan
[root@VM-12-11-centos /]#

删除容器

[root@VM-12-11-centos /]# docker -rm 容器Id					#删除指定容器, 不能删除运行中的容器
[root@VM-12-11-centos /]# docker rm -f $(docker ps -aq)	 #删除所有的容器,可以删除运行中的容器

[root@VM-12-11-centos /]# docker ps -a
CONTAINER ID   IMAGE         COMMAND       CREATED          STATUS                        PORTS     NAMES
9d0cf7e6ea19   centos        "/bin/bash"   4 minutes ago    Up 4 minutes                            youthful_hermann
4f8480af2cb9   centos        "/bin/bash"   14 minutes ago   Exited (130) 11 minutes ago             reverent_morse
254da3bb3c70   hello-world   "/hello"      25 hours ago     Exited (0) 25 hours ago                 inspiring_elbakyan
[root@VM-12-11-centos /]# docker rm 4f8480af2cb9
4f8480af2cb9
[root@VM-12-11-centos /]# docker ps -a
CONTAINER ID   IMAGE         COMMAND       CREATED          STATUS                    PORTS     NAMES
9d0cf7e6ea19   centos        "/bin/bash"   16 minutes ago   Up 16 minutes                       youthful_hermann
254da3bb3c70   hello-world   "/hello"      25 hours ago     Exited (0) 25 hours ago             inspiring_elbakyan
# 运行中的容器不能删除
[root@VM-12-11-centos /]# docker rm 9d0cf7e6ea19
Error response from daemon: You cannot remove a running container 9d0cf7e6ea198f6c5a6cedea90bf3667a4fec67d798a0e25d83dfcefdc6b2693. Stop the container before attempting removal or force remove
# 可以删除运行中的容器
[root@VM-12-11-centos /]# docker rm -f $(docker ps -aq)
9d0cf7e6ea19
254da3bb3c70

查看容器Id

# 第一行打印的Id 就是容器的id
docker inspect 容器名

启动停止容器

docker start 容器Id		# 启动容器
docker restart 容器Id		# 重启容器
docker stop 容器Id		# 停止容器
docker kill 容器Id		# 强制结束容器进程

# 首先启动容器, 然后退出
[root@VM-12-11-centos /]# docker run -it centos
[root@786922be077d /]# exit
exit

# 查看容器Id
[root@VM-12-11-centos /]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS                     PORTS     NAMES
786922be077d   centos    "/bin/bash"   11 seconds ago   Exited (0) 7 seconds ago             kind_liskov

# 根据容器Id启动容器
[root@VM-12-11-centos /]# docker start 786922be077d
786922be077d

# 根据容器Id停止容器
[root@VM-12-11-centos /]# docker stop 786922be077d
786922be077d

# 查看容器已经停止
[root@VM-12-11-centos /]# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES
786922be077d   centos    "/bin/bash"   3 minutes ago   Exited (0) 3 seconds ago             kind_liskov

常用其他命令

后台启动容器

# 启动后又立即关闭,因为当前容器并没有运行的程序,导致容器停止
[root@VM-12-11-centos /]# docker run -d centos
90fd7f71028c600eaaf0f6682c72f21d4dd6850f59c156d182d87ff88fddd19a

查看日志

[root@VM-12-11-centos /]# docker logs --help

Usage:  docker logs [OPTIONS] CONTAINER

Fetch the logs of a container

Options:
      --details        Show extra details provided to logs
  -f, --follow         Follow log output
      --since string   Show logs since timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
  -n, --tail string    Number of lines to show from the end of the logs (default "all")
  -t, --timestamps     Show timestamps
      --until string   Show logs before a timestamp (e.g. 2013-01-02T13:23:37Z) or relative (e.g. 42m for 42 minutes)
      
      
      
#查看日志, Ctrl + C 退出查看的日志
[root@VM-12-11-centos /]# docker logs -tf --tail 10 b64cc5a0b6a5
2021-12-14T13:57:52.503943466Z [root@b64cc5a0b6a5 /]# docker ps
2021-12-14T13:57:52.504392832Z bash: docker: command not found

查看容器中的进程信息

[root@VM-12-11-centos /]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
b64cc5a0b6a5   centos    "/bin/bash"   15 minutes ago   Up 15 minutes             loving_curran
[root@VM-12-11-centos /]# docker top b64cc5a0b6a5
UID		PID		PPID		C 		STIME		TTY		TIME		CMD
root 	23480  	23460 		0 		21:57 		?		00:00:00  	/bin/bash

查看镜像元数据

[root@VM-12-11-centos /]# docker inspect --help

Usage:  docker inspect [OPTIONS] NAME|ID [NAME|ID...]

Return low-level information on Docker objects

Options:
  -f, --format string   Format the output using the given Go template
  -s, --size            Display total file sizes if the type is container
      --type string     Return JSON for specified type
[root@VM-12-11-centos /]# docker inspect b64cc5a0b6a5
[
    {
        "Id": "b64cc5a0b6a51b5800ca9f0b9602e35c65552c1d1613597582b443c77a5c9e60",
        "Created": "2021-12-14T13:57:44.411892616Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 23480,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-12-14T13:57:44.694761002Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/b64cc5a0b6a51b5800ca9f0b9602e35c65552c1d1613597582b443c77a5c9e60/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/b64cc5a0b6a51b5800ca9f0b9602e35c65552c1d1613597582b443c77a5c9e60/hostname",
        "HostsPath": "/var/lib/docker/containers/b64cc5a0b6a51b5800ca9f0b9602e35c65552c1d1613597582b443c77a5c9e60/hosts",
        "LogPath": "/var/lib/docker/containers/b64cc5a0b6a51b5800ca9f0b9602e35c65552c1d1613597582b443c77a5c9e60/b64cc5a0b6a51b5800ca9f0b9602e35c65552c1d1613597582b443c77a5c9e60-json.log",
        "Name": "/loving_curran",
        "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/75b2c6107f41bfd0a3c381eb19d4830c67f96b0643a72dd9c6d81773ca0d6ab0-init/diff:/var/lib/docker/overlay2/d69ec46ce46d4360c7a351b6684c9e0a0e4197498ce306f5addffcf11613147d/diff",
                "MergedDir": "/var/lib/docker/overlay2/75b2c6107f41bfd0a3c381eb19d4830c67f96b0643a72dd9c6d81773ca0d6ab0/merged",
                "UpperDir": "/var/lib/docker/overlay2/75b2c6107f41bfd0a3c381eb19d4830c67f96b0643a72dd9c6d81773ca0d6ab0/diff",
                "WorkDir": "/var/lib/docker/overlay2/75b2c6107f41bfd0a3c381eb19d4830c67f96b0643a72dd9c6d81773ca0d6ab0/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "b64cc5a0b6a5",
            "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": "20210915",
                "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": "c41ce2ba14223635d7c0b4b46b6d87ca78ee375b9105a276680184cd42602355",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/c41ce2ba1422",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "2a5a204517ba9fffb1e8a1f678fbc5392bc6b635902ad10965958e68adacc816",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.3",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:03",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "ac12bc9a2fa28b76eca2110c70d840be0fcc0db3c174e2fa8d9d02774315ba20",
                    "EndpointID": "2a5a204517ba9fffb1e8a1f678fbc5392bc6b635902ad10965958e68adacc816",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]

进入当前运行的容器

[root@VM-12-11-centos /]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS         PORTS     NAMES
b64cc5a0b6a5   centos    "/bin/bash"   30 minutes ago   Up 3 seconds             loving_curran
# docker exec -it 容器Id  COMMAND 
[root@VM-12-11-centos /]# docker exec -it b64cc5a0b6a5 /bin/bash
[root@b64cc5a0b6a5 /]#

# 进入当前正在运行的命令行
[root@VM-12-11-centos /]# docker attach b64cc5a0b6a5
[root@b64cc5a0b6a5 /]#

docker exec		# 进入容器后开启一个新的终端,可以在里面进行操作(常用)
docker attach	# 进入容器正在执行的终端,不会启动新的进程

从容器内拷贝文件到主机

拷贝是手动的操作,后续的话会使用卷的技术,将两个文件进行同步,修改一个文件,另一个文件也同步进行修改

docker cp 容器Id:容器内路径  目的的主机路径

新建测试文件

[root@VM-12-11-centos home]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
b64cc5a0b6a5   centos    "/bin/bash"   45 minutes ago   Up 14 minutes             loving_curran
[root@VM-12-11-centos home]# docker attach b64cc5a0b6a5
[root@b64cc5a0b6a5 /]# cd /home/
[root@b64cc5a0b6a5 home]# ls
[root@b64cc5a0b6a5 home]# touch testFileInContainer.txt
[root@b64cc5a0b6a5 home]# ls
testFileInContainer.txt

退出容器,进行拷贝

[root@VM-12-11-centos home]# docker ps
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS          PORTS     NAMES
b64cc5a0b6a5   centos    "/bin/bash"   48 minutes ago   Up 18 minutes             loving_curran
[root@VM-12-11-centos home]# ls
lighthouse
[root@VM-12-11-centos home]# docker cp b64cc5a0b6a5:/home/testFileInContainer.txt /home
[root@VM-12-11-centos home]# ls
lighthouse  testFileInContainer.txt

查看命令【万能命令】

[root@VM-12-11-centos etc]# docker --help

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default "/root/.docker")
  -c, --context string     Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context
                           set with "docker context use")
  -D, --debug              Enable debug mode
  -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:
  app*        Docker App (Docker Inc., v0.9.1-beta3)
  builder     Manage builds
  buildx*     Build with BuildKit (Docker Inc., v0.6.3-docker)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  scan*       Docker Scan (Docker Inc., v0.9.0)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  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 codes

Run 'docker COMMAND --help' for more information on a command.

To get more help with docker, check out our guides at https://docs.docker.com/go/guides/

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-12-15 18:43:00  更:2021-12-15 18:44:19 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/16 5:34:48-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码