Docker镜像以及仓库详解
Docker镜像就是一个Linux的文件系统(Root FileSystem),这个文件系统里面包含可以运行在Linux内核的程序以及相应的数据。
Linux Docker、Swarm、 Kubernetes分布式微服务部署云原生实战地址:https://www.itying.com/goods-1155.html(视频+课件+源码) Docker B站学习地址:https://www.bilibili.com/video/BV1LQ4y127qT?p=1
1、docker search 搜索镜像
docker search centos
[root@localhost /]# docker search --help
Usage: docker search [OPTIONS] TERM
Search the Docker Hub for images
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
docker search mysql
备注:-f STARS=3000搜索STARS大于3000的镜像
[root@localhost /]# docker search mysql -f STARS=3000
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
mysql MySQL is a widely used, open-source relation… 11171 [OK]
mariadb MariaDB Server is a high performing open sou… 4242 [OK]
2、 docker pull下载镜像
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
下载指定的tag:
docker pull centos:8.3.2011
[root@localhost /]# docker pull centos:8.3.2011
8.3.2011: Pulling from library/centos
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for centos:8.3.2011
docker.io/library/centos:8.3.2011
3、docker images查看本地镜像
docker images
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
centos latest 300e315adb2f 7 months ago 209MB
4、docker tag给镜像打标签
给镜像打标签可以创建自己的镜像 镜像结构: registryname/repositoryname/imagename:tagname 例如:docker.io/library/centos:8.3.2011
基本语法:
[root@localhost /]# docker tag --help
Usage: docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
centos 8.3.2011 300e315adb2f 7 months ago 209MB
centos latest 300e315adb2f 7 months ago 209MB
给 IMAGE ID为 300e315adb2f的镜像打个标签
docker tag 300e315adb2f docker.io/itying/centos:v1.0.1
[root@localhost /]# docker tag 300e315adb2f docker.io/itying/centos:v1.0.1
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
itying/centos v1.0.1 300e315adb2f 7 months ago 209MB
centos 8.3.2011 300e315adb2f 7 months ago 209MB
centos latest 300e315adb2f 7 months ago 209MB
给 IMAGE ID为 300e315adb2f的镜像重新打个latest标签
[root@localhost /]# docker tag 300e315adb2f docker.io/itying/centos:latest
[root@localhost /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 months ago 13.3kB
centos 8.3.2011 300e315adb2f 7 months ago 209MB
centos latest 300e315adb2f 7 months ago 209MB
itying/centos latest 300e315adb2f 7 months ago 209MB
itying/centos v1.0.1 300e315adb2f 7 months ago 209MB
5、docker rmi删除镜像
查看本地镜像
[root@localhost /]# docker images | grep centos
itying/centos latest 300e315adb2f 7 months ago 209MB
itying/centos v1.0.1 300e315adb2f 7 months ago 209MB
centos 8.3.2011 300e315adb2f 7 months ago 209MB
centos latest 300e315adb2f 7 months ago 209MB
[root@localhost /]# docker rmi docker.io/itying/centos:latest
Untagged: itying/centos:latest
这样删除只会删除对应的标签
[root@localhost /]# docker images | grep centos
itying/centos v1.0.1 300e315adb2f 7 months ago 209MB
centos 8.3.2011 300e315adb2f 7 months ago 209MB
centos latest 300e315adb2f 7 months ago 209MB
要删除imagesID为300e315adb2f的镜像需要通过id删除
[root@localhost /]# docker rmi -f 300e315adb2f
Untagged: itying/centos:v1.0.1
Untagged: centos:8.3.2011
Untagged: centos:latest
Untagged: centos@sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Deleted: sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55
Deleted: sha256:2653d992f4ef2bfd27f94db643815aa567240c37732cae1405ad1c1309ee9859
[root@localhost /]# docker images | grep centos
这样就会删除imagesID为300e315adb2f的centos镜像
6、把本地镜像推送到dockerHub仓库
一、需要在dockerHub上面注册一个账户:https://hub.docker.com/ 二、使用 docker login本地登录dockerHub
docker login
[root@localhost ~]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: itying
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
查看保存的账户信息
[root@localhost ~]# cat .docker/config.json
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "aXR5aW5nOnpoYW5nxxG9uZzEyMzQ="
}
}
}