阿里云镜像加速
1、登录阿里云找到容器服务
2、找到镜像加速的地址
3、配置使用
$sudo mkdir -p /etc/docker
$sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors":["https://bruce_liu1973@163.com.mirror.aliyuncs.com"]
}
EOF
$sudo systemctl daemon-reload
$sudo systemctl restart docker
回顾HelloWorld流程
1、开始---->docker在本机寻找镜像---->判断是否存在 ---->存在启动本机镜像
2、开始---->docker在本机寻找镜像---->判断是否存在 ---->不存在---->去docker hub下载----->找到下载到本地---->启动
底层原理
Docker是怎么工作的?
1、Docker是一个Client-Server结构的系统,Docker的守护进程(daemon)运行在主机上。通过Socket从客户端访问
2、DockerServer接收到Docker-Client的指令,就会执行这个命令
Docker的常用命令
docker info #显示docker的系统信息,包括镜像和容器的数量
docker version #显示docker的版本信息
docker --help #帮助命令
帮助文档的地址:https://docs.docker.com/engine/reference/commandline/
镜像命令
1、docker images 查看所有本地的主机上的镜像
# Windows系统环境
C:\cmder
λ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker/getting-started latest 26d80cd96d69 4 weeks ago 28.5MB
docker/desktop-kubernetes kubernetes-v1.22.4-cni-v0.8.5-critools-v1.17.0-debian 493a106d3678 6 weeks ago 294MB
scrapinghub/splash latest 9364575df985 16 months ago 1.89GB
# 解释
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的id
CREATED 镜像的创建时间
SIZE 镜像的大小
# 可选项
Options:
-a, --all Show all images (default hides intermediate images) # 列出所有镜像 -q, --quiet Only show image IDs # 只显示ID
2、docker search搜索镜像
官网地址:https://hub.docker.com/
# Windows系统环境
docker search mysql
C:\cmder
λ docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11909 [OK]
mariadb MariaDB Server is a high performing open sou… 4556 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 894 [OK]
# 可选项
docker search --help
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
#通过收藏来过滤
--filter=STARS=3000 # 搜索出来的镜像就是STARS超过3000的
C:\cmder
λ docker search mysql --filter=STARS=4000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11909 [OK]
mariadb MariaDB Server is a high performing open sou… 4556 [OK]
docker pull 下载镜像
# Windows系统环境
C:\cmder
λ docker pull --help
Usage: docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Pull an image or a repository from a registry
Options:
-a, --all-tags Download all tagged images in the repository
--disable-content-trust Skip image verification (default true)
--platform string Set platform if server is multi-platform
capable
-q, --quiet Suppress verbose output
# 下载镜像
C:\cmder
λ docker pull mysql
Using default tag: latest #如果不写tag,默认就是latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete # 分层下载,docker images的核心,联合文件系统
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 # 签名
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest # 真实地址
# 等价命令
docker pull mysql
docker pull docker.io/library/mysql:latest
# 下载镜像 指定版本
docker pull mysql:5.7
C:\cmder
λ docker pull mysql:5.7
5.7: Pulling from library/mysql
72a69066d2fe: Already exists
93619dbc5b36: Already exists
99da31dd6142: Already exists
626033c43d70: Already exists
37d5d7efb64e: Already exists
ac563158d721: Already exists
d2ba16033dad: Already exists
0ceb82207cd7: Pull complete
37f2405cae96: Pull complete
e2482e017e53: Pull complete
70deed891d42: Pull complete
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
# 查看所有的镜像
docker 删除镜像
docker rmi -f c20987f18b13 # image id 删除指定的镜像
docker rmi -f 容器id 容器id 容器id 容器id #删除多个容器
docker rmi -f $(docker images -aq) #删除所有的镜像 -aq是所有的镜像 $()传参