倉庫是集中存放鏡像的地方。
註冊服務器:它是存放倉庫的具體服務器,每一個註冊服務器上能夠有多個倉庫,每一個倉庫裏面能夠有多個鏡像。
#1.docker公共倉庫
Docker官方公共倉庫:https://hub.docker.com
登陸:採用docker login 命令來輸入用戶名、密碼來完成登陸。php
[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: panda30 Password: Login Succeeded [root@localhost /]#
搜索鏡像:採用docker search命令java
[root@localhost /]# docker search centos INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.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命令linux
[root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE panda30/test latest ace789a750cc 2 weeks ago 129.5 MB test latest ace789a750cc 2 weeks ago 129.5 MB docker.io/ubuntu latest f49eec89601e 8 weeks ago 129.5 MB [root@localhost /]# docker pull centos Using default tag: latest Trying to pull repository docker.io/library/centos ... latest: Pulling from docker.io/library/centos 785fe1d06b2d: Pull complete Digest: sha256:be5b4a93f116a57ab3fd454ada72421eac892a3a4925627ac9a44f65fcd69cf8 [root@localhost /]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos latest 98d35105a391 4 days ago 192.5 MB panda30/test latest ace789a750cc 2 weeks ago 129.5 MB test latest ace789a750cc 2 weeks ago 129.5 MB docker.io/ubuntu latest f49eec89601e 8 weeks ago 129.5 MB [root@localhost /]#
#2.建立和使用私有倉庫
2.1 建立私有倉庫nginx
[root@localhost /]# docker pull registry Using default tag: latest Trying to pull repository docker.io/library/registry ... latest: Pulling from docker.io/library/registry 709515475419: Pull complete df6e278d8f96: Pull complete 16218e264e88: Pull complete 16748da81f63: Pull complete 8d73e673c34c: Pull complete Digest: sha256:28be0609f90ef53e86e1872a11d672434ce1361711760cf1fe059efd222f8d37 [root@localhost /]#
經過該鏡像啓動一個容器docker
[root@localhost /]# docker run -d -p 5000:5000 registry 01318e76816cef2ab6970711c7149a64326c66895109f702b6cd203235386a68 [root@localhost /]#
這樣,就建立了本地私有倉庫。
查看docker信息apache
[root@localhost /]# docker info Containers: 2 Running: 1 Paused: 0 Stopped: 1 Images: 4 Server Version: 1.12.5 Storage 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: journald Cgroup Driver: systemd Plugins: Volume: local Network: host overlay bridge null Swarm: inactive Runtimes: docker-runc runc Default Runtime: docker-runc Security Options: seccomp Kernel Version: 3.10.0-123.el7.x86_64 Operating System: CentOS Linux 7 (Core) OSType: linux Architecture: x86_64 Number of Docker Hooks: 2 CPUs: 1 Total Memory: 1.791 GiB Name: localhost.localdomain ID: LNVV:PGU3:XOWM:XE7D:VJZX:4YTN:MEGF:HY5K:GLYU:YKME:Q5VO:H2EB Docker Root Dir: /var/lib/docker Debug Mode (client): false Debug Mode (server): false Username: panda30 Registry: https://index.docker.io/v1/ WARNING: bridge-nf-call-iptables is disabled WARNING: bridge-nf-call-ip6tables is disabled Insecure Registries: 127.0.0.0/8 Registries: docker.io (secure) [root@localhost /]#
由docker info可知
目前容器有2個(一個運行中,一箇中止);4個鏡像;服務器版本:1.12.5l;docker的根路徑:/var/lib/docker。
這樣就在本地啓動了一個私有倉庫服務,監聽端口爲5000,以下ubuntu
[root@localhost /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fd44f1c4adf0 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
查看容器ipcentos
[root@localhost /]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fd44f1c4adf0 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 SIZE docker.io/centos latest 98d35105a391 6 days ago 192.5 MB docker.io/registry latest 047218491f8c 2 weeks ago 33.17 MB panda30/test latest ace789a750cc 3 weeks ago 129.5 MB test latest ace789a750cc 3 weeks ago 129.5 MB docker.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 SIZE docker.io/centos latest 98d35105a391 6 days ago 192.5 MB 172.17.0.2/16/test latest 047218491f8c 2 weeks ago 33.17 MB docker.io/registry latest 047218491f8c 2 weeks ago 33.17 MB panda30/test latest ace789a750cc 3 weeks ago 129.5 MB test latest ace789a750cc 3 weeks ago 129.5 MB docker.io/ubuntu latest f49eec89601e 8 weeks ago 129.5 MB [root@localhost /]#