docker官方命令参考文档: https://docs.docker.com/reference
查看docker版本
[root@VM-12-11-centos etc]
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]
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
--no-trunc
-q, --quiet
[root@VM-12-11-centos etc]
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
[root@VM-12-11-centos etc]
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest bbf6571db497 12 days ago 516MB
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
[root@VM-12-11-centos etc]
bbf6571db497
feb5d9fea6a5
搜索镜像——镜像命令
- 可以去官网进行搜索,有更明细的信息可以进行查看
- 没有注册的可以先去官网注册, 注册教程:docker 镜像注册【图文教程】
- docker镜像官网:https://hub.docker.com
[root@VM-12-11-centos etc]
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]
Using default tag: latest
latest: Pulling from library/mysql
ffbb094f4f9e: Pull complete
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]
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]
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
[root@VM-12-11-centos etc]
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]
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest bbf6571db497 12 days ago 516MB
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
[root@VM-12-11-centos etc]
容器命令
说明:有了镜像之后才可以创建容器,Linux,下载一个Centos镜像测试学习
新建容器并启动
[root@VM-12-11-centos etc]
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]
名称,简写 | 默认 | 描述 |
---|
--add-host | | 添加自定义主机到 IP 映射 (host:ip) | --attach , -a | | 附加到 STDIN、STDOUT 或 STDERR | --blkio-weight | | Block 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-count | | CPU 计数(仅限 Windows) | --cpu-percent | | CPU 百分比(仅限 Windows) | --cpu-period | | 限制 CPU CFS(完全公平调度程序)周期 | --cpu-quota | | 限制 CPU CFS(完全公平调度程序)配额 | --cpu-rt-period | | API 1.25+ 以微秒为单位限制 CPU 实时周期 | --cpu-rt-runtime | | API 1.25+ 以微秒为单位限制 CPU 实时运行时间 | --cpu-shares , -c | | CPU份额(相对权重) | --cpus | | API 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-trust | true | 跳过图像验证 | --dns | | 设置自定义 DNS 服务器 | --dns-opt | | 设置 DNS 选项 | --dns-option | | 设置 DNS 选项 | --dns-search | | 设置自定义 DNS 搜索域 | --domainname | | 容器NIS域名 | --entrypoint | | 覆盖图像的默认 ENTRYPOINT | --env , -e | | 设置环境变量 | --env-file | | 读入环境变量文件 | --expose | | 公开一个端口或一系列端口 | --gpus | | API 1.40+ 要添加到容器中的 GPU 设备(‘all’ 以传递所有 GPU) | --group-add | | 添加要加入的其他组 | --health-cmd | | 运行以检查健康状况的命令 | --health-interval | | 运行检查之间的时间(ms|s|m|h)(默认为 0s) | --health-retries | | 报告不健康需要连续失败 | --health-start-period | | API 1.29+ 在开始健康重试倒计时(ms|s|m|h)之前容器初始化的开始时间(默认为 0s) | --health-timeout | | 允许运行一次检查的最长时间(ms|s|m|h)(默认为 0s) | --help | | 打印使用 | --hostname , -h | | 容器主机名 | --init | | API 1.25+ 在容器内运行一个 init 来转发信号和收获进程 | --interactive , -i | | 即使未连接,也要保持 STDIN 打开 | --io-maxbandwidth | | 系统驱动器的最大 IO 带宽限制(仅限 Windows) | --io-maxiops | | 系统驱动器的最大 IOps 限制(仅限 Windows) | --ip | | IPv4 地址(例如 172.30.100.104) | --ip6 | | IPv6 地址(例如,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 表示无限制) | --platform | | API 1.32+ 如果服务器支持多平台,则设置平台 | --privileged | | 授予此容器扩展权限 | --publish , -p | | 将容器的端口发布到主机 | --publish-all , -P | | 将所有暴露的端口发布到随机端口 | --pull | missing | 运行前拉取镜像(“总是”|“缺失”|“从不”) | --read-only | | 将容器的根文件系统挂载为只读 | --restart | no | 容器退出时应用的重启策略 | --rm | | 退出时自动移除容器 | --runtime | | 用于此容器的运行时 | --security-opt | | 安全选项 | --shm-size | | /dev/shm 的大小 | --sig-proxy | true | 代理接收到进程的信号 | --stop-signal | SIGTERM | 停止容器的信号 | --stop-timeout | | API 1.25+ 停止容器的超时(以秒为单位) | --storage-opt | | 容器的存储驱动程序选项 | --sysctl | | sysctl 选项 | --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]
--name
-d
-it
-P
-P ip:主机端口:容器端口
-P 容器端口
容器端口(直接写端口, 不使用-P标识)
-p
启动并进入容器
[root@VM-12-11-centos etc]
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]
[root@4f8480af2cb9 /]
exit
[root@VM-12-11-centos etc]
查看所有运行中的容器
[root@VM-12-11-centos /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@VM-12-11-centos /]
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]
[root@4f8480af2cb9 /]
exit
[root@VM-12-11-centos etc]
退出容器并在后台运行 ——快速按 Ctrl + P + Q
[root@VM-12-11-centos /]
[root@9d0cf7e6ea19 /]
[root@VM-12-11-centos /]
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 /]
[root@VM-12-11-centos /]
[root@VM-12-11-centos /]
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 /]
4f8480af2cb9
[root@VM-12-11-centos /]
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 /]
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 /]
9d0cf7e6ea19
254da3bb3c70
查看容器Id
docker inspect 容器名
启动停止容器
docker start 容器Id
docker restart 容器Id
docker stop 容器Id
docker kill 容器Id
[root@VM-12-11-centos /]
[root@786922be077d /]
exit
[root@VM-12-11-centos /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
786922be077d centos "/bin/bash" 11 seconds ago Exited (0) 7 seconds ago kind_liskov
[root@VM-12-11-centos /]
786922be077d
[root@VM-12-11-centos /]
786922be077d
[root@VM-12-11-centos /]
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 /]
90fd7f71028c600eaaf0f6682c72f21d4dd6850f59c156d182d87ff88fddd19a
查看日志
[root@VM-12-11-centos /]
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)
[root@VM-12-11-centos /]
2021-12-14T13:57:52.503943466Z [root@b64cc5a0b6a5 /]
2021-12-14T13:57:52.504392832Z bash: docker: command not found
查看容器中的进程信息
[root@VM-12-11-centos /]
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 /]
UID PID PPID C STIME TTY TIME CMD
root 23480 23460 0 21:57 ? 00:00:00 /bin/bash
查看镜像元数据
[root@VM-12-11-centos /]
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 /]
[
{
"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 /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b64cc5a0b6a5 centos "/bin/bash" 30 minutes ago Up 3 seconds loving_curran
[root@VM-12-11-centos /]
[root@b64cc5a0b6a5 /]
[root@VM-12-11-centos /]
[root@b64cc5a0b6a5 /]
docker exec
docker attach
从容器内拷贝文件到主机
拷贝是手动的操作,后续的话会使用卷的技术,将两个文件进行同步,修改一个文件,另一个文件也同步进行修改
docker cp 容器Id:容器内路径 目的的主机路径
新建测试文件
[root@VM-12-11-centos home]
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]
[root@b64cc5a0b6a5 /]
[root@b64cc5a0b6a5 home]
[root@b64cc5a0b6a5 home]
[root@b64cc5a0b6a5 home]
testFileInContainer.txt
退出容器,进行拷贝
[root@VM-12-11-centos home]
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]
lighthouse
[root@VM-12-11-centos home]
[root@VM-12-11-centos home]
lighthouse testFileInContainer.txt
查看命令【万能命令】
[root@VM-12-11-centos etc]
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/
|