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的基本命令

镜像命令

[root@VM-8-14-centos docker]# docker images
# 解释
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   5 months ago   13.3kB
REPOSITORY	镜像的仓库源
TAG			镜像的标签
IMAGE ID 	镜像的id
CREATED		镜像的创建时间
SIZE		镜像的大小
# 可选项
-a, --all	#列出所有的命令
-q,--quiet #只显示id

docker search 搜索镜像

[root@VM-8-14-centos docker]# docker search mysql
NAME                         DESCRIPTION                                     STARS    
mysql                        MySQL is a widely used, open-source relation…   11294         
mariadb                      MariaDB Server is a high performing open sou…   4289           
mysql/mysql-server           Optimized MySQL Server Docker images. Create…   837           
#可选项  通过收藏来过滤
--filter=STARS=3000		搜索出来的镜像就是STARS数量大于3000的

docker pull 下载镜像

[root@VM-8-14-centos docker]# docker pull mysql
Using default tag: latest			#没写tag的话,默认是使用最新版本latest
latest: Pulling from library/mysql
e1acddbe380c: Pulling fs layer 		#分层下载,docker的核心,联合文件系统
bed879327370: Pulling fs layer 
03285f80bafd: Pulling fs layer 
ccc17412a00a: Pull complete 
1f556ecc09d1: Pull complete 
adc5528e468d: Pull complete 
1afc286d5d53: Pull complete 
6c724a59adff: Pull complete 
0f2345f8b0a3: Pull complete 
c8461a25b23b: Pull complete 
3adb49279bed: Pull complete 
77f22cd6c363: Pull complete 
Digest: sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926	#签名
Status: Downloaded newer image for mysql:latest	
docker.io/library/mysql:latest		#真实地址

#docker pull mysql 等价于 docker pull docker.io/library/mysql:latest


#指定版本下载
[root@VM-8-14-centos docker]# docker pull mysql:5.7
5.7: Pulling from library/mysql
e1acddbe380c: Already exists 	#已经有了的就不会进行下载
bed879327370: Already exists 	#这样更节省内存
03285f80bafd: Already exists 
ccc17412a00a: Already exists 
1f556ecc09d1: Already exists 
adc5528e468d: Already exists 
1afc286d5d53: Already exists 
4d2d9261e3ad: Pull complete 	#只下载了四个层级
ac609d7b31f8: Pull complete 
53ee1339bc3a: Pull complete 
b0c0a831a707: Pull complete 
Digest: sha256:7cf2e7d7ff876f93c8601406a5aa17484e6623875e64e7acc71432ad8e0a3d7e
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

docker 删除镜像

#通过id删除一个镜像,也可以通过名字删除
[root@VM-8-14-centos docker]# docker rmi -f 6c20ffa54f86
Untagged: mysql:5.7
Untagged: mysql@sha256:7cf2e7d7ff876f93c8601406a5aa17484e6623875e64e7acc71432ad8e0a3d7e
Deleted: sha256:6c20ffa54f8674203e91e3225e489aa505fa04b8d482954a8b6d7414842c6de4
Deleted: sha256:7ecf077dd9d6725f0e594b9cd5eb214ad1b3764fa75bf5940ab08b05b8bae184
Deleted: sha256:c28edab85681de37f9d2a75dde941a20d2e1ac6e4efb7dee391913d3ec722fef
Deleted: sha256:6c11b187da1ecb65ce10b25f54354f3515ce9d26fabcd859cdb43dbd625df907
Deleted: sha256:d0dfc5be0883ed4af9f642a8e4f2312a93c4241ec8e89f22219b0f0a0d26c8d3


#删除所有的docker镜像
[root@VM-8-14-centos docker]# docker rmi -f $(docker images -aq)
Untagged: mysql:latest
Untagged: mysql@sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926
Deleted: sha256:5a4e492065c722ec8cc7413552bafc6fd5434c5ad90797e898ccc4e347e21aa5
Deleted: sha256:816bf92c28337cd97393cb1fab7697398c9b657baa8e80ad394e1193bdd7c323
Deleted: sha256:4d9cad11f64589b397b1033d6f14cea1794efbee0a9923932fb3394a67cb9812
Deleted: sha256:d8cc28a31b469770ffe2239a29aaef8745fedc4df3c545b1615ba864796709a3
Deleted: sha256:c65a377e07f1205f3c28f7067d2ac4da3a65fbe7c1b4606b48028db3818d2f4c
Deleted: sha256:7dcd840f1d4be1a565f470453489932a17c62ed36b959d7839f004606ba22f0b
Deleted: sha256:1438a7497295aed687ea1875073a1f9faa6a308f787767b952da4a1a21e2c2c6
Deleted: sha256:c728863b4742db55b9630b0129abac718c8c9704e5ed86e8af93dfb47a0f6214
Deleted: sha256:0f12df3ff796b6fb619c63bf2f78f16d1033746e19f75ffc2d8d72ea69242ad4
Deleted: sha256:3072318e40ebff019298a59290e615ad6170a651f3121c0e356dcf3dd7426136
Deleted: sha256:a69e3133dd3c0a81bd439120abb8f98e43c1581629896725b968db906c8fdfac
Deleted: sha256:6d9498fd63c38c4b0b9bbc563087b4bc164b2fb5211832a8d43c60a9692a7f84
Deleted: sha256:f68ef921efae588b3dd5cc466a1ca9c94c24785f1fa9420bea15ecc2dedbe781
Untagged: hello-world:latest
Untagged: hello-world@sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726

#查看剩余的docker镜像
[root@VM-8-14-centos docker]# docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

容器命令

说明:我们有了镜像才可以创建容器,linux,下载一个centos镜像来测试学习

docker pull centos

新建容器并启动

docker run [可选参数] image

#参数说明
--name="Name" 	容器名字	tomcat1 tomcat2 用于区分容器
-d				后台方式运行
-it	 			使用交互方式运行,进入容器查看内容
-p				指定容器的端口 -p 8080:8080
			-p ip:主机端口:容器端口
			-p 主机端口:容器端口(常用)
			-p 容器端口
			容器端口
#测试		启动并进入容器
[root@VM-8-14-centos docker]# docker run -it centos /bin/bash
[root@ac71b5898083 /]# 

[root@ac71b5898083 /]# ls	#查看容器内的centos,基础版本,很多命令都不完善
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

#退出容器命令
[root@9af1a7b253ec /]# exit
exit
[root@VM-8-14-centos /]# 

列出所有运行的容器

#docker ps 命令
		#列出当前正在运行的容器
-a		#列出当前正在运行的容器+历史运行过的容器
-n=?	#显示最近创建的容器
-q		#只显示容器的编号

[root@VM-8-14-centos /]# docker ps  #运行的容器
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

[root@VM-8-14-centos /]# docker ps -a   #运行过的容器
CONTAINER ID   IMAGE          COMMAND       CREATED              STATUS                          PORTS     NAMES
9af1a7b253ec   centos         "/bin/bash"   About a minute ago   Exited (0) About a minute ago             happy_nash
ac71b5898083   centos         "/bin/bash"   3 minutes ago        Exited (0) 2 minutes ago                  sleepy_sutherland
e1c59d0e993b   d1165f221234   "/hello"      24 hours ago         Exited (0) 24 hours ago                   quizzical_albattani
[root@VM-8-14-centos /]# 

退出容器

exit	#容器直接停止退出
Ctrl+P+Q #不停止退出

删除容器

docker rm 容器id						#删除指定的容器,不能删除正在运行的容器,如果要强制删除就rm -f
docker rm -f $(docker ps -aq)		 #删除所有的容器	
docker ps -a -q|xargs docker rm		 #删除所有的容器

启动和停止容器的操作

docker start 容器id		#启动容器
docker restart 容器id		#重启容器
docker stop 容器id		#停止当前正在运行的容器
docker kill 容器id		#强制停止当前容器

常用其他命令

后台启动容器

#命令docker run -d 镜像名!
[root@VM-8-14-centos /]# docker run -d centos
#问题 docker ps 发现centos 停止了
#docker容器使用后台运行,就必须要有一个前台进程,否则docker发现没有应用,就会自动停止
#例如nginx,容器启动后,发现自己没有提供服务,就会立即停止,就是没有程序了

查看日志

[root@VM-8-14-centos /]# docker run -d centos /bin/bash -c "while true;do echo fanxu;sleep 1;done" 
88e36a8819f26f5d12a8fd658adfbb97ed60901a71a8d878a0d8174b98b72dd7


[root@VM-8-14-centos /]# docker logs -tf --tail 10 88e36a8819f2
2021-08-18T14:17:58.098503211Z fanxu
2021-08-18T14:17:59.100849355Z fanxu
2021-08-18T14:18:00.103158743Z fanxu
2021-08-18T14:18:01.105462026Z fanxu
2021-08-18T14:18:02.107828632Z fanxu

查看容器中进程信息

[root@VM-8-14-centos /]# docker top 81d323846d11
UID       PID       PPID      C         STIME     TTY            TIME         CMD
root      20586     20568     0         22:20     pts/0          00:00:00     /bin/bash

查看镜像的源数据

#命令
docker inspect 容器id

[root@VM-8-14-centos /]# docker inspect 81d323846d11
[
    {
        "Id": "81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02",
        "Created": "2021-08-18T14:20:55.98150614Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 21525,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-08-18T14:24:47.97344561Z",
            "FinishedAt": "2021-08-18T14:21:26.415512597Z"
        },
        "Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
        "ResolvConfPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/hostname",
        "HostsPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/hosts",
        "LogPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02-json.log",
        "Name": "/sad_dewdney",
        "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/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e-init/diff:/var/lib/docker/overlay2/ceeaa5c3fbacd569a80e013cd1a6b907befa0d99540989b93b8815c9bf1451bb/diff",
                "MergedDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/merged",
                "UpperDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/diff",
                "WorkDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "81d323846d11",
            "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": "20201204",
                "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": "23b5413c3d4ff11d5cb5b1d93acd35c3132ca7e5183fc178179f89436b0dda23",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/23b5413c3d4f",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "e834842300b4afe5cbf75789ec9e534acc1d62235e9efd0cbd305dbcf9c8e488",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "603e3599e40881a802fb09405c7bb535241e86cd1ae9671bad557dead6b9a31b",
                    "EndpointID": "e834842300b4afe5cbf75789ec9e534acc1d62235e9efd0cbd305dbcf9c8e488",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-08-19 12:28:08  更:2021-08-19 12:29:48 
 
开发: 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/15 9:54:07-

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