容器,镜像和仓库的关系
- 容器是由镜像实例化出来,镜像是容器的模板,容器也可以提交成镜像
- 镜像可以从仓库拉取到本地,也可以将镜像从本地推送到仓库
Docker Hub
Docker hub是docker最大的镜像仓库,可以先在dockerhub.com注册一个账号,方便后续会用到。
[root@ip-10-0-0-45 ec2-user]#docker login docker.io //登陆你的docker hub账号,输入dockerhub注册的账号密码
username:
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
搜索一个镜像
镜像的结构:registry_name/repository_name/image_name:tag_name
例如:docker.io/library/alpine:3.10.1
[root@ip-10-0-0-45 ec2-user]#docker search alpine
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 6533 [OK]
ansible/centos7-ansible Ansible on Centos7 134 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC session… 128 [OK]
jdeathe/centos-ssh OpenSSH / Supervisor / EPEL/IUS/SCL Repos - … 118 [OK]
centos/systemd systemd enabled base container. 98 [OK]
centos/mysql-57-centos7 MySQL 5.7 SQL database server 87
imagine10255/centos6-lnmp-php56 centos6-lnmp-php56 58 [OK]
tutum/centos Simple CentOS docker image with SSH access 48
kinogmt/centos-ssh CentOS with SSH 29 [OK]
pivotaldata/centos-gpdb-dev CentOS image for GPDB development. Tag names… 13
guyton/centos6 From official centos6 container with full up… 10 [OK]
centos/tools Docker image that has systems administration… 7 [OK]
drecom/centos-ruby centos ruby 6 [OK]
pivotaldata/centos Base centos, freshened up a little with a Do… 5
pivotaldata/centos-gcc-toolchain CentOS with a toolchain, but unaffiliated wi… 3
mamohr/centos-java Oracle Java 8 Docker image based on Centos 7 3 [OK]
pivotaldata/centos-mingw Using the mingw toolchain to cross-compile t… 3
darksheer/centos Base Centos Image -- Updated hourly 3 [OK]
indigo/centos-maven Vanilla CentOS 7 with Oracle Java Developmen… 2 [OK]
amd64/centos The official build of CentOS. 2
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
pivotaldata/centos6.8-dev CentosOS 6.8 image for GPDB development 1
mcnaughton/centos-base centos base image 1 [OK]
smartentry/centos centos with smartentry 0 [OK]
pivotaldata/centos7-dev CentosOS 7 image for GPDB development 0
下载镜像
通过docker pull 拉取镜像 ,默认tag为latest,也可以下载直接的tag
[root@ip-10-0-0-45 ec2-user]# docker pull alpine //默认tag
Using default tag: latest
latest: Pulling from library/alpine
540db60ca938: Pull complete
Digest: sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
[root@ip-10-0-0-45 ec2-user]# docker pull alpine:3.10.3//指定tag
3.10.3: Pulling from library/alpine
89d9c30c1d48: Pull complete
Digest: sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a
Status: Downloaded newer image for alpine:3.10.3
docker.io/library/alpine:3.10.3
查看本地镜像
[root@ip-10-0-0-45 ec2-user]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 6dbb9cc54074 3 weeks ago 5.61MB
hello-world latest d1165f221234 2 months ago 13.3kB
alpine 3.10.3 965ea09ff2eb 18 months ago 5.55MB
给镜像打标签
[root@ip-10-0-0-45 ec2-user]# docker tag 965ea09ff2eb docker.io/58440236/alpine:v3.10.3
[root@ip-10-0-0-45 ec2-user]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 6dbb9cc54074 3 weeks ago 5.61MB
hello-world latest d1165f221234 2 months ago 13.3kB
58440236/alpine v3.10.3 965ea09ff2eb 18 months ago 5.55MB
alpine 3.10.3 965ea09ff2eb 18 months ago 5.55MB
推送镜像
[root@ip-10-0-0-45 ec2-user]# docker push docker.io/58440236/alpine:v3.10.3
The push refers to repository [docker.io/58440236/alpine]
77cae8ab23bf: Mounted from library/alpine
v3.10.3: digest: sha256:e4355b66995c96b4b468159fc5c7e3540fcef961189ca13fee877798649f531a size: 528
推送完之后,我们可以在dockerhub上看到我们推送上去的镜像
删除镜像
[root@ip-10-0-0-45 ec2-user]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest 6dbb9cc54074 3 weeks ago 5.61MB
hello-world latest d1165f221234 2 months ago 13.3kB
58440236/alpine v3.10.3 965ea09ff2eb 18 months ago 5.55MB
alpine 3.10.3 965ea09ff2eb 18 months ago 5.55MB
[root@ip-10-0-0-45 ec2-user]# docker rmi alpine //删除镜像
Untagged: alpine:latest
Untagged: alpine@sha256:69e70a79f2d41ab5d637de98c1e0b055206ba40a8145e7bddb55ccc04e13cf8f
Deleted: sha256:6dbb9cc54074106d46d4ccb330f2a40a682d49dda5f4844962b7dce9fe44aaec
Deleted: sha256:b2d5eeeaba3a22b9b8aa97261957974a6bd65274ebd43e1d81d0a7b8b752b116
[root@ip-10-0-0-45 ec2-user]# docker rmi alpine -f 965ea09ff2eb//也可以通过image id 删除
Untagged: 58440236/alpine:v3.10.3
Untagged: 58440236/alpine@sha256:e4355b66995c96b4b468159fc5c7e3540fcef961189ca13fee877798649f531a
Untagged: alpine:3.10.3
Untagged: alpine@sha256:c19173c5ada610a5989151111163d28a67368362762534d8a8121ce95cf2bd5a
Deleted: sha256:965ea09ff2ebd2b9eeec88cd822ce156f6674c7e99be082c7efac3c62f3ff652
Deleted: sha256:77cae8ab23bf486355d1b3191259705374f4a11d483b24964d2f729dd8c076a0
[root@ip-10-0-0-45 ec2-user]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 2 months ago 13.3kB