安装
1.卸载旧版本
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
2.需要的安装包
yum install -y yum-utils
3.设置镜像的仓库
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
上述方法默认是从国外的,不推荐
推荐使用国内的
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- 更新
yum
软件包索引
yum makecache fast
4.安装docker
相关的docker-ce
社区版 而ee是企业版
yum install docker-ce docker-ce-cli containerd.io
- 这里我们使用社区版即可
5.启动docker
(重启 service docker restart
)
[root@VM-0-6-centos ~]# systemctl start docker
[root@VM-0-6-centos ~]# service docker restart // 重启docker
Redirecting to /bin/systemctl restart docker.service
- 使用
docker version
查看是否安装成功
docker version
- 测试
docker run hello-world
8.查看已经下载的镜像 (从这里可以查看已有镜像的id)
[root@VM-0-6-centos /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 3 months ago 13.3kB
卸载 docker
- 卸载依赖
yum remove docker-ce docker-ce-cli containerd.io
- 删除资源
rm -rf /var/lib/docker
-
/var/lib/docker
是docker的默认工作路径!
Docker 的常用命令
- 帮助命令
docker version # 显示docker的版本信息。
docker info # 显示docker的系统信息,包括镜像和容器的数量
docker 命令 --help # 帮助命令
- 镜像命令
docker images # 查看所有本地主机上的镜像 可以使用docker image ls代替
docker search # 搜索镜像
docker pull # 下载镜像 docker image pull
docker rmi # 删除镜像 docker image rm
-
docker images
查看所有本地的主机上的镜像
[root@VM-0-6-centos /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 3 months ago 13.3kB
# 解释
# REPOSITORY # 镜像的仓库源
# TAG # 镜像的标签(版本) ---lastest 表示最新版本
# IMAGE ID # 镜像的id
# CREATED # 镜像的创建时间
# SIZE # 镜像的大小
# 可选项
Options:
-a, --all Show all images (default hides intermediate images) # 列出所有镜像
-q, --quiet Only show numeric IDs # 只显示镜像的id
[root@VM-0-6-centos ~]# docker images -a # 列出所有镜像详细信息
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 3 months ago 13.3kB
[root@VM-0-6-centos ~]# docker images -aq # 列出所有镜像的id
d1165f221234
-
docker search
搜索镜像
[root@VM-0-6-centos ~]# docker search mysql # 搜索镜像
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11013 [OK]
mariadb MariaDB Server is a high performing open sou… 4173 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 819 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 88
mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 87
centurylink/mysql Image containing mysql. Optimized to be link… 59 [OK]
bitnami/mysql Bitnami MySQL Docker Image 52 [OK]
databack/mysql-backup Back up mysql databases to... anywhere! 44
deitch/mysql-backup REPLACED! Please use http://hub.docker.com/r… 41 [OK]
-
--filter=STARS=3000
# 过滤,搜索镜像收藏STARS数量大于3000的
Options:
-f, --filter filter Filter output based on conditions provided
--format string Pretty-print search using a Go template
--limit int Max number of search results (default 25)
--no-trunc Don't truncate output
[root@VM-0-6-centos ~]# docker search mysql --filter=STARS=3000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11013 [OK]
mariadb MariaDB Server is a high performing open sou… 4173 [OK]
-
docker pull
下载镜像
# 下载镜像 docker pull 镜像名[:tag]
[root@VM-0-6-centos ~]# docker pull node:lts-alpine3.13
lts-alpine3.13: Pulling from library/node # 如果不写tag,默认就是latest
540db60ca938: Pull complete #分层下载: docker image 的核心 联合文件系统
d1d4e8cc8684: Pull complete
0ed82e007932: Pull complete
a888d19c6548: Pull complete
Digest: sha256:6a5aad5c5a56fdce1303bd622426818d2a767b6179be0fba62e0e5f45ea6604e # 签名防伪
Status: Downloaded newer image for node:lts-alpine3.13
docker.io/library/node:lts-alpine3.13 #真实地址
docker pull node:lts-alpine3.13
// 等价于
docker pull docker.io/library/node:lts-alpine3.13
-
docker rmi
删除镜像
docker rmi -f 镜像id # 删除指定id的镜像
[root@VM-0-6-centos ~]# docker rmi a0aa4dac325b
Untagged: tomcat:8
Untagged: tomcat@sha256:cc0466b0009605b8059684afd04eecd008dd911bbb65e5b06a2423791856c4d8
Deleted: sha256:a0aa4dac325ba805f9772de4c2601c10d84378a847620a17749ef89094d57f8b
Deleted: sha256:7789ffa41c0d233daf1b5360277b1e458020a1bb5c629f5b1ffecc5cd40e43f3
Deleted: sha256:1ae6e6f428ce08ad87ca052502bc39c2a4d103654c029663855502d35391cebe
Deleted: sha256:ca33f3ac112feff53226c7779c5dcf6d9228d243a8003112af6e97b1cbe8adf9
Deleted: sha256:a1ebb61f926c6adb4be953d5fa465ad632e0f280d666290131c40402869da050
Deleted: sha256:8322a18d091807c0b67edd4c8b80a8302e55c538427a5350e626f13fe111553b
Deleted: sha256:7d9015a7e7cc4ffda4712793436cecdd5572df6e80ee67912a76a6442c448b2d
Deleted: sha256:1405602eb1a912ad0bef3b35fc79f4a1eb332cd3ff05b36b560dad11e8d8ca7f
Deleted: sha256:1a126caa7f2df8ccb95a4a08242b527fe3268eebf55cdd72b5b6a7aafd908519
Deleted: sha256:b639806ab48953fe53941bccbaaecc99d82e693585e7b818ff9a6413ef519f25
Deleted: sha256:688e187d6c79c46e8261890f0010fd5d178b8faa178959b0b46b2635aa1eeff3
- 删除全部的镜像
docker rmi -f $(docker images -aq) # 删除全部的镜像