1. 镜像的结构

- docker镜像是一个典型的分层结构
- 只有最上面一层是可写的 其他都是只读的固化到镜像的
- 每次推送都是增量的

镜像名称的结构
${registry_name}/${repository_name}/${image_name}:${tag_name}# 远端仓库地址/仓库名字/镜像名:镜像标签(即版本号)
例如:
docker.io/library/alpine:3.10.3
2. 注册DockerHub
dockerhub:全球最大的docker官方镜像仓库,开源免费。
地址:https://hub.docker.com/
邮箱验证 —-> 登录
2.1 docker登录dockerhub:
登录到docker.io
[root@localhost ~]# docker login docker.ioLogin 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: zhanghb123Password:WARNING! Your password will be stored unencrypted in /root/.docker/config.json.Configure a credential helper to remove this warning. Seehttps://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded[root@localhost ~]#
2.2 查看已登录信息
[root@localhost ~]# cat /root/.docker/config.json{"auths": {"https://index.docker.io/v1/": {"auth": "emhhbmdoYjEyMzpaaGIxMjMzMjFA"}}}[root@localhost ~]#注: 此处的密码可以用echo "5bCP5LiR56uf5Zyo5oiR6Lqr6L65" |base64 -d 进行解码
3. 搜索镜像
dockerhub 官方镜像,也可以在浏览器登录dockerhub网页搜索
Alpine 操作系统是一个面向安全的轻型 Linux 发行版。
[root@localhost ~]# docker search alpineNAME DESCRIPTION STARS OFFICIAL AUTOMATEDalpine A minimal Docker image based on Alpine Linux… 7337 [OK]mhart/alpine-node Minimal Node.js built on Alpine Linux 483anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.28 over A… 468 [OK]frolvlad/alpine-glibc Alpine Docker image with glibc (~12MB) 259 [OK]gliderlabs/alpine Image based on Alpine Linux will help you wi… 183alpine/git A simple git container running in alpine li… 175 [OK]yobasystems/alpine-mariadb MariaDB running on Alpine Linux [docker] [am… 86 [OK]alpine/socat Run socat command in alpine container 68 [OK]kiasaki/alpine-postgres PostgreSQL docker image based on Alpine Linux 44 [OK]davidcaste/alpine-tomcat Apache Tomcat 7/8 using Oracle Java 7/8 with… 44 [OK]jfloff/alpine-python A small, more complete, Python Docker image … 40 [OK]byrnedo/alpine-curl Alpine linux with curl installed and set as … 34 [OK]hermsi/alpine-sshd Dockerize your OpenSSH-server with rsync and… 33 [OK]zenika/alpine-chrome Chrome running in headless mode in a tiny Al… 31 [OK]hermsi/alpine-fpm-php FPM-PHP 7.0 to 8.0, shipped along with tons … 25 [OK]etopian/alpine-php-wordpress Alpine WordPress Nginx PHP-FPM WP-CLI 24 [OK]bashell/alpine-bash Alpine Linux with /bin/bash as a default she… 18 [OK]davidcaste/alpine-java-unlimited-jce Oracle Java 8 (and 7) with GLIBC 2.21 over A… 13 [OK]roribio16/alpine-sqs Dockerized ElasticMQ server + web UI over Al… 12 [OK]spotify/alpine Alpine image with `bash` and `curl`. 11 [OK]cfmanteiga/alpine-bash-curl-jq Docker Alpine image with Bash, curl and jq p… 6 [OK]bushrangers/alpine-caddy Alpine Linux Docker Container running Caddys… 1 [OK]ellerbrock/alpine-mysql-client MySQL Client based on Alpine Linux 1 [OK]dwdraju/alpine-curl-jq Alpine Docker Image with curl, jq, bash 1 [OK]goodguykoi/alpine-curl-internal simple alpine image with curl installed no C… 1 [OK][root@localhost ~]#
4. 拉取镜像
如果不指定tag 默认下载最新版本 latest
[root@localhost ~]# docker pull alpineUsing default tag: latestlatest: Pulling from library/alpine540db60ca938: Pull completeDigest: sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8fStatus: Downloaded newer image for alpine:latestdocker.io/library/alpine:latest # 仓库地址/仓库/镜像名:标签(版本)[root@localhost ~]#
指定下载版本:
[root@localhost ~]# docker pull alpine:3.10.33.10.3: Pulling from library/alpine89d9c30c1d48: Pull completeDigest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5aStatus: Downloaded newer image for alpine:3.10.3docker.io/library/alpine:3.10.3[root@localhost ~]## 如果使用官方的docker.io 可以不写前面的docker.io/library/ 因为默认就是公开的 如果是自己的或者其他仓库 需要写全
5. 镜像打标签
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalpine latest 6dbb9cc54074 2 days ago 5.61MBalpine 3.10.3 965ea09ff2eb 18 months ago 5.55MB[root@localhost ~]# docker tag 965ea09ff2eb docker.io/zhanghb123/alpine:v3.10.3[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalpine latest 6dbb9cc54074 2 days ago 5.61MBalpine 3.10.3 965ea09ff2eb 18 months ago 5.55MBzhanghb123/alpine v3.10.3 965ea09ff2eb 18 months ago 5.55MB[root@localhost ~]## IMAGE ID相同的话说明镜像是一样的 前面的tag只是一个指针 就像软链接
6. 推送至远程仓库
[root@localhost ~]# docker push docker.io/zhanghb123/alpine:v3.10.3The push refers to repository [docker.io/zhanghb123/alpine]77cae8ab23bf: Mounted from library/alpinev3.10.3: digest: sha256:e4355b66995c96b4b468159fc5c7e3540fcef961189ca13fee877798649f531a size: 528[root@localhost ~]#
7. 删除镜像
[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalpine latest 6dbb9cc54074 2 days ago 5.61MBzhanghb123/alpine v3.10.3 965ea09ff2eb 18 months ago 5.55MBalpine 3.10.3 965ea09ff2eb 18 months ago 5.55MB[root@localhost ~]# docker rmi 965ea09ff2ebError response from daemon: conflict: unable to delete 965ea09ff2eb (must be forced) - image is referenced in multiple repositories # #这个ID有多个tag 所以需要用-f 来删除[root@localhost ~]# docker rmi -f 965ea09ff2ebUntagged: alpine:3.10.3Untagged: alpine@sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a # 先去掉tag再删除Untagged: zhanghb123/alpine:v3.10.3Untagged: zhanghb123/alpine@sha256:e4355b66995c96b4b468159fc5c7e3540fcef961189ca13fee877798649f531aDeleted: sha256:965ea09ff2ebd2b9eeec88cd822ce156f6674c7e99be082c7efac3c62f3ff652Deleted: sha256:77cae8ab23bf486355d1b3191259705374f4a11d483b24964d2f729dd8c076a0[root@localhost ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEalpine latest 6dbb9cc54074 2 days ago 5.61MB[root@localhost ~]## 上面的删除操作只是删除了本地的镜像,不会对远程仓库的镜像产生影响

