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/engine/reference/commandline/docker/

1.镜像命令

1.docker version

????????显示docker的版本信息

?

2.docker info

? ? ? ? 显示更完全的信息

?

3.docker images

[root@localhost /]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   4 months ago   13.3kB
  • repository? ? ? ? 镜像的仓库源
  • tag? ? ? ? ? ? ? ? ? ?镜像的标签
  • image id? ? ? ? ? 镜像的id
  • created? ? ? ? ? ? 镜像创建的时间
  • size? ? ? ? ? ? ? ? ? 镜像的大小
[root@localhost /]# docker images --help

Usage:  docker images [OPTIONS] [REPOSITORY[:TAG]]

List images

Options:
  -a, --all             Show all images (default hides intermediate images)
      --digests         Show digests
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print images using a Go template
      --no-trunc        Don't truncate output
  -q, --quiet           Only show image IDs
  • -a? ? 显示所有的镜像
  • -q? ? 只显示镜像的id
  • -f? ? ?过滤镜像

4.docker search

命令行:

docker search [软件名]

或者我们也可用通过docker官网来搜索,我们可以在里面看到版本号等更详细的信息。

https://hub.docker.com/

我们可以根据它的版本号进行下载?

我们还可以用命令行搜索

?搜索mysql

5.docker pull 下载镜像

根据上面docker search的搜索,我们可以根据docker的搜索下载,比我们下载tomcat:

[root@localhost /]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
627b765e08d1: Pull complete 
c040670e5e55: Pull complete 
073a180f4992: Pull complete 
bf76209566d0: Pull complete 
f10db7ba7580: Pull complete 
5b2f970878fa: Pull complete 
ed434bfebf18: Pull complete 
f6c437110aa9: Pull complete 
a772951f83db: Pull complete 
752225c3768e: Pull complete 
Digest: sha256:6e40250d8fac4eca05c2067cb81f79427e4ddbaf4e78d5ecd21c35e8c5f2bfcf
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest

然后我们看下下载的镜像大小:

[root@localhost /]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
tomcat        latest    46cfbf1293b1   5 days ago     668MB
hello-world   latest    d1165f221234   4 months ago   13.3kB

我淦,怎么下个tomcat这么大?

指定版本下载:

docker pull mysql:5.7?

6.docker rmi 删除镜像

删除下载的tomcat

docker rmi tomcat

[root@localhost /]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
tomcat        latest    46cfbf1293b1   5 days ago     668MB
hello-world   latest    d1165f221234   4 months ago   13.3kB
[root@localhost /]# docker rmi 46cfbf1293b1
Untagged: tomcat:latest
Untagged: tomcat@sha256:6e40250d8fac4eca05c2067cb81f79427e4ddbaf4e78d5ecd21c35e8c5f2bfcf
Deleted: sha256:46cfbf1293b176161813fa05bb8f7e82df1ec7def5c226c48bc48a60ed305ac7
Deleted: sha256:6748c687a38bae8ee5179c1b7c3fc05347dab445a5322f30e62c80348997d99c
Deleted: sha256:4e78f4eefb564a3492c5840bfcf17a0bed07fda1e59127c66058dd7553ed7f9b
Deleted: sha256:99b6cc44dbf7b0b4809ede178ae7fb27fef1401c8b2415be0dc18b6153ff233f
Deleted: sha256:046e7218b905a3de840f00a2aa7081fc53ace4ffba9661d471d59bfdcfa5b4c1
Deleted: sha256:3095bb61fd62bf2c2fd6849289c6043e8866bf104ca0959be3fc3da5bab0be1e
Deleted: sha256:f33d6ed931ff64c63168af00c7544d148d01fda66831246572ff2bfcacbcf2d6
Deleted: sha256:017b9704876de2443b332b1dfec580d365184b514eb0af43f1d59637e77af9bb
Deleted: sha256:98fc59c935e697d6375f05f4fa29d0e1ef7e8ece61aed109056926983ada0ef4
Deleted: sha256:c21ff68b02e7caf277f5d356e8b323a95e8d3969dd1ab0d9f60e7c8b4a01c874
Deleted: sha256:afa3e488a0ee76983343f8aa759e4b7b898db65b715eb90abc81c181388374e3

删除所有的docker镜像

docker rmi -f $(docker images -aq)

2.容器命令

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

docker pull centos
[root@localhost /]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
7a0437f04f83: Pull complete 
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
[root@localhost /]# 

新建容器并启动

docker run[可选参数] image
docker run [可选参数] image | docker container run [可选参数] image 
#参书说明
--name="Name"		#容器名字 tomcat01 tomcat02 用来区分容器
-d					#后台方式运行
-it 				#使用交互方式运行,进入容器查看内容
-p					#指定容器的端口 -p 8080(宿主机):8080(容器)
		-p ip:主机端口:容器端口
		-p 主机端口:容器端口(常用)
		-p 容器端口
		容器端口
-P(大写) 				随机指定端口

# 测试、启动并进入容器

启动并进入我们安装的centos的容器

[root@localhost ~]# docker run -it centos /bin/bash
[root@1fdd979c08c7 /]# 

我们查看一下这个容器里面的内容:

[root@1fdd979c08c7 /]# ls -l
total 0
lrwxrwxrwx.   1 root root   7 Nov  3  2020 bin -> usr/bin
drwxr-xr-x.   5 root root 360 Jul 28 14:48 dev
drwxr-xr-x.   1 root root  66 Jul 28 14:48 etc
drwxr-xr-x.   2 root root   6 Nov  3  2020 home
lrwxrwxrwx.   1 root root   7 Nov  3  2020 lib -> usr/lib
lrwxrwxrwx.   1 root root   9 Nov  3  2020 lib64 -> usr/lib64
drwx------.   2 root root   6 Dec  4  2020 lost+found
drwxr-xr-x.   2 root root   6 Nov  3  2020 media
drwxr-xr-x.   2 root root   6 Nov  3  2020 mnt
drwxr-xr-x.   2 root root   6 Nov  3  2020 opt
dr-xr-xr-x. 122 root root   0 Jul 28 14:48 proc
dr-xr-x---.   2 root root 162 Dec  4  2020 root
drwxr-xr-x.  11 root root 163 Dec  4  2020 run
lrwxrwxrwx.   1 root root   8 Nov  3  2020 sbin -> usr/sbin
drwxr-xr-x.   2 root root   6 Nov  3  2020 srv
dr-xr-xr-x.  13 root root   0 Jul 28 14:34 sys
drwxrwxrwt.   7 root root 145 Dec  4  2020 tmp
drwxr-xr-x.  12 root root 144 Dec  4  2020 usr
drwxr-xr-x.  20 root root 262 Dec  4  2020 var
[root@1fdd979c08c7 /]# 

从上面我们可以看到,在这个容器里面的结构和我们新装的Linux的结构差不多。但是这个容器里面的很多命令是不完善的。

退出容器:exit

?查看所有运行的容器:

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@localhost ~]# 

从上面可以看出,目前docker中没有运行的系统,可以查看ps的所有命令。

[root@localhost ~]# docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display container IDs
  -s, --size            Display total file sizes
[root@localhost ~]# 

2.1 退出容器

我们之前使用exit直接退出容器,那么我们怎样让系统在后台运行呢?

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

删除容器

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         #强制停止容器

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

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