Docker工作原理
Docker是一个C/S结构的系统,Docker的守护进程运行在主机上,通过Socket从客户端访问。
DockerServer接收到DockerClient的命令就会执行。
Docker为什么比虚拟机快?
- Docker具有比虚拟机更少的抽象层
- Docker利用的是宿主机的内核,vm需要虚拟化一个单独的内核(创建容器时,不需要重新加载一个操作系统内核,不需要进行引导)
Docker常用命令
docker version #版本信息
docker info #详细信息
docker 命令 --help # 帮助
镜像命令
docker images
查看本地所有镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 7 months ago 13.3kB
- REPOSITORY 仓库原
- TAG 仓库标签
- IMAGE ID 镜像id
- CREATED 镜像的创建时间
- SIZE 大小
可选项
- -a 显示全部
- -f 过滤
- -q 仅显示id
docker search
搜索命令
[root@iZ8vbioqlrpr01woefafo2Z ~]# docker search mysql
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 12483 [OK]
mariadb MariaDB Server is a high performing open sou… 4806 [OK]
mysql/mysql-server Optimized MySQL Server Docker images. Create… 924 [OK]
percona Percona Server is a fork of the MySQL relati… 575 [OK]
phpmyadmin phpMyAdmin - A web interface for MySQL and M… 516 [OK]
# ......
可选项
- filter
--filter =stars=3000
(收藏数大于3000的镜像)
docker pull
下载命令
默认使用最新版,等价于docker pull xx:latest
[root@iZ8vbioqlrpr01woefafo2Z ~]# docker pull mysql
Using default tag: latest # 默认最新版本
latest: Pulling from library/mysql
# 分层下载,docker image的核心 联合文件系统
72a69066d2fe: Pull complete
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:5.7
[root@iZ8vbioqlrpr01woefafo2Z ~]# 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 rmi -f + id
[root@iZ8vbioqlrpr01woefafo2Z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 c20987f18b13 4 months ago 448MB
mysql latest 3218b38490ce 4 months ago 516MB
hello-world latest feb5d9fea6a5 7 months ago 13.3kB
[root@iZ8vbioqlrpr01woefafo2Z ~]#
[root@iZ8vbioqlrpr01woefafo2Z ~]# docker rmi -f c20987f18b13
Untagged: mysql:5.7
Untagged: mysql@sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Deleted: sha256:c20987f18b130f9d144c9828df630417e2a9523148930dc3963e9d0dab302a76
Deleted: sha256:6567396b065ee734fb2dbb80c8923324a778426dfd01969f091f1ab2d52c7989
Deleted: sha256:0910f12649d514b471f1583a16f672ab67e3d29d9833a15dc2df50dd5536e40f
Deleted: sha256:6682af2fb40555c448b84711c7302d0f86fc716bbe9c7dc7dbd739ef9d757150
Deleted: sha256:5c062c3ac20f576d24454e74781511a5f96739f289edaadf2de934d06e910b92
[root@iZ8vbioqlrpr01woefafo2Z ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 3218b38490ce 4 months ago 516MB
hello-world latest feb5d9fea6a5 7 months ago 13.3kB
docker rmi -f $(docker images -aq)
删除全部容器