仓库是集中存放镜像的地方。
注册服务器:它是存放仓库的具体服务器,每个注册服务器上可以有多个仓库,每个仓库里面可以有多个镜像。 #1.docker公共仓库 Docker官方公共仓库: 登录:采用docker login 命令来输入用户名、密码来完成登录。[root@localhost /]# docker loginLogin 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: panda30Password: Login Succeeded[root@localhost /]#
搜索镜像:采用docker search命令
[root@localhost /]# docker search centosINDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATEDdocker.io docker.io/centos The official build of CentOS. 3177 [OK] docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.8 x86_64 / CentOS-7 7.3.1611 x8... 62 [OK]docker.io docker.io/jdeathe/centos-ssh-apache-php CentOS-6 6.8 x86_64 - Apache / PHP-FPM / P... 25 [OK]docker.io docker.io/nimmis/java-centos This is docker images of CentOS 7 with dif... 23 [OK]docker.io docker.io/consol/centos-xfce-vnc Centos container with "headless" VNC sessi... 22 [OK]docker.io docker.io/gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glu... 18 [OK]docker.io docker.io/torusware/speedus-centos Always updated official CentOS docker imag... 8 [OK]docker.io docker.io/egyptianbman/docker-centos-nginx-php A simple and highly configurable docker co... 6 [OK]docker.io docker.io/nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... 5 [OK]docker.io docker.io/centos/mariadb55-centos7 4 [OK][root@localhost /]#
拉取镜像,采用 docker pull命令
[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZEpanda30/test latest ace789a750cc 2 weeks ago 129.5 MBtest latest ace789a750cc 2 weeks ago 129.5 MBdocker.io/ubuntu latest f49eec89601e 8 weeks ago 129.5 MB[root@localhost /]# docker pull centosUsing default tag: latestTrying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos785fe1d06b2d: Pull complete Digest: sha256:be5b4a93f116a57ab3fd454ada72421eac892a3a4925627ac9a44f65fcd69cf8[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos latest 98d35105a391 4 days ago 192.5 MBpanda30/test latest ace789a750cc 2 weeks ago 129.5 MBtest latest ace789a750cc 2 weeks ago 129.5 MBdocker.io/ubuntu latest f49eec89601e 8 weeks ago 129.5 MB[root@localhost /]#
#2.创建和使用私有仓库
2.1 创建私有仓库[root@localhost /]# docker pull registryUsing default tag: latestTrying to pull repository docker.io/library/registry ... latest: Pulling from docker.io/library/registry709515475419: Pull complete df6e278d8f96: Pull complete 16218e264e88: Pull complete 16748da81f63: Pull complete 8d73e673c34c: Pull complete Digest: sha256:28be0609f90ef53e86e1872a11d672434ce1361711760cf1fe059efd222f8d37[root@localhost /]#
通过该镜像启动一个容器
[root@localhost /]# docker run -d -p 5000:5000 registry01318e76816cef2ab6970711c7149a64326c66895109f702b6cd203235386a68[root@localhost /]#
这样,就创建了本地私有仓库。
查看docker信息[root@localhost /]# docker info Containers: 2 Running: 1 Paused: 0 Stopped: 1Images: 4Server Version: 1.12.5Storage Driver: devicemapper Pool Name: docker-253:1-202234675-pool Pool Blocksize: 65.54 kB Base Device Size: 10.74 GB Backing Filesystem: xfs Data file: /dev/loop0 Metadata file: /dev/loop1 Data Space Used: 475.5 MB Data Space Total: 107.4 GB Data Space Available: 33.67 GB Metadata Space Used: 1.171 MB Metadata Space Total: 2.147 GB Metadata Space Available: 2.146 GB Thin Pool Minimum Free Space: 10.74 GB Udev Sync Supported: true Deferred Removal Enabled: false Deferred Deletion Enabled: false Deferred Deleted Device Count: 0 Data loop file: /var/lib/docker/devicemapper/devicemapper/data WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device. Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata Library Version: 1.02.135-RHEL7 (2016-11-16)Logging Driver: journaldCgroup Driver: systemdPlugins: Volume: local Network: host overlay bridge nullSwarm: inactiveRuntimes: docker-runc runcDefault Runtime: docker-runcSecurity Options: seccompKernel Version: 3.10.0-123.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64Number of Docker Hooks: 2CPUs: 1Total Memory: 1.791 GiBName: localhost.localdomainID: LNVV:PGU3:XOWM:XE7D:VJZX:4YTN:MEGF:HY5K:GLYU:YKME:Q5VO:H2EBDocker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseUsername: panda30Registry: https://index.docker.io/v1/WARNING: bridge-nf-call-iptables is disabledWARNING: bridge-nf-call-ip6tables is disabledInsecure Registries: 127.0.0.0/8Registries: docker.io (secure)[root@localhost /]#
由docker info可知
目前容器有2个(一个运行中,一个停止);4个镜像;服务器版本:1.12.5l;docker的根路径:/var/lib/docker。 这样就在本地启动了一个私有仓库服务,监听端口为5000,如下[root@localhost /]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESfd44f1c4adf0 registry "/entrypoint.sh /etc/" 5 minutes ago Up 5 minutes 0.0.0.0:5000->5000/tcp admiring_bassi[root@localhost /]#
可以看到ports的值为0.0.0.0:5000
查看容器ip[root@localhost /]# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESfd44f1c4adf0 registry "/entrypoint.sh /etc/" 9 minutes ago Up 9 minutes 0.0.0.0:5000->5000/tcp admiring_bassi[root@localhost /]# docker exec -it fd44f1c4adf03e58d0066f7cbeccd802099c46e74ffa5a78b847f281e29a2f5c ip addr | grep global inet 172.17.0.2/16 scope global eth0[root@localhost /]#
使用docker tag将这个镜像标记
[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos latest 98d35105a391 6 days ago 192.5 MBdocker.io/registry latest 047218491f8c 2 weeks ago 33.17 MBpanda30/test latest ace789a750cc 3 weeks ago 129.5 MBtest latest ace789a750cc 3 weeks ago 129.5 MBdocker.io/ubuntu latest f49eec89601e 8 weeks ago 129.5 MB[root@localhost /]# docker tag registry 172.17.0.2/16/test[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZEdocker.io/centos latest 98d35105a391 6 days ago 192.5 MB172.17.0.2/16/test latest 047218491f8c 2 weeks ago 33.17 MBdocker.io/registry latest 047218491f8c 2 weeks ago 33.17 MBpanda30/test latest ace789a750cc 3 weeks ago 129.5 MBtest latest ace789a750cc 3 weeks ago 129.5 MBdocker.io/ubuntu latest f49eec89601e 8 weeks ago 129.5 MB[root@localhost /]#