第一节环境准备
软件
docker:18.09.6
registry:2.x
主机
docker120:192.168.68.120
DServer140:192.168.68.140
实验环境
[root@DServer140 ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@DServer140 ~]# systemctl stop firewalld
[root@DServer140 ~]# systemctl disable firewalld
[root@DServer140 ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@DServer140 ~]# setenforce 0
[root@DServer140 ~]# yum -y install iptables-services
[root@DServer140 ~]# iptables -F
[root@DServer140 ~]# service iptables save
第二节docker安装
[root@DServer140 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@DServer140 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@DServer140 ~]# yum install docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io -y
[root@DServer140 ~]# systemctl start docker
[root@DServer140 ~]# systemctl disable docker
第三节仓库安装
[root@DServer140 ~]# docker search registry | head -2
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
registry The Docker Registry 2.0 implementation for s… 2657 [OK]
[root@DServer140 ~]# docker pull registry
[root@DServer140 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest f32a97de94e1 5 months ago 25.8MB
[root@DServer140 ~]# mkdir /data/registry -p
[root@DServer140 ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /data/registry/:/var/lib/registry registry:latest
--restart=always 该always表示会使docker daemon退出重启后容器服务自动恢复,不必再docker start ... (容器随服务启动而启动)
[root@DServer140 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2158e14b53ba registry:latest "/entrypoint.sh /etc…" 5 seconds ago Up 3 seconds 0.0.0.0:5000->5000/tcp registry
第四节测试
命令:
打标签
docker tag 镜像ID 仓库IP:端口/标签名
提交仓库
docker push 仓库IP:端口/标签名
从仓库拉去镜像
docker pull 仓库IP:端口/标签名
实战:
客户端docker120
[root@docker120 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx <none> e445ab08b2be 3 weeks ago 126MB
[root@docker120 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx <none> e445ab08b2be 3 weeks ago 126MB
[root@docker120 ~]# docker tag e445ab08b2be 192.168.68.140:5000/test
[root@docker120 ~]# docker push 192.168.68.140:5000/test
The push refers to repository [192.168.68.140:5000/test]
fe6a7a3b3f27: Pushed
d0673244f7d4: Pushed
d8a33133e477: Pushed
latest: digest: sha256:dc85890ba9763fe38b178b337d4ccc802874afe3c02e6c98c304f65b08af958f size: 948
服务端DServer140
[root@DServer140 ~]# curl -XGET http://192.168.68.140:5000/v2/_catalog
{"repositories":["test"]}
[root@DServer140 ~]# curl -XGET http://192.168.68.140:5000/v2/test/tags/list
{"name":"test","tags":["latest"]}
温馨提示:
1,设置docker自动提示功能
[root@DServer140 ~]# yum -y install bash-completion
[root@DServer140 ~]# source /etc/profile.d/bash_completion.sh
[root@DServer140 ~]# docker
attach create history kill node push save stats trust
build diff image load pause rename search stop unpause
commit events images login plugin restart secret swarm update
config exec import logout port rm service system version
container export info logs ps rmi stack tag volume
cp help inspect network pull run start top wait
以后docker [tab] [tab]就出来提示了,很方便!
2、提交镜像时提示 http: server gave HTTP response to HTTPS client
解决办法:
[root@docker120 ~]# vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.68.140:5000"]
}
[root@docker120 ~]# systemctl restart docker
结束语:
更多精彩内容持续更新中,关注我微信公众号,有你更精彩。