docker 创建本地镜像服务器

时间:2022-09-10 21:00:47
1.docker pull registry //下载registry 镜像,registry 为docker 官方提供的一个镜像,

我们可以用它来创建本地的docker私有仓库。

docker:/root# docker images | grep registry
registry latest 07d93e41c370 7 weeks ago 422.8 MB 2.docker run -d -p 5000:5000 registry //以registry 镜像启动容器,监听5000端口 -p 左边是宿主机的端口 右边是容器端口 做映射 curl 127.0.0.1:5000 docker:/root# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
402620f666c1 registry "docker-registry" About a minute ago Up About a minute 0.0.0.0:5000->5000/tcp gloomy_brown
docker:/root# docker exec -it 402620f666c1 bash
root@402620f666c1:/# docker:/root# curl 127.0.0.1:5000
"\"docker-registry server\""docker:/root# docker0 Link encap:Ethernet HWaddr 16:7B:77:6E:E5:4A
inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0 docker:/root# docker tag centos 172.17.42.1:5000/zjzc-test01 docker:/root# docker tag centos 192.168.32.150:5000/zjzc-test02 docker:/root# docker images | grep 5000
172.17.42.1:5000/zjzc-test01 latest bb3d629a7cbc 13 days ago 196.6 MB
192.168.32.150:5000/zjzc-test02 latest bb3d629a7cbc 13 days ago 196.6 MB
docker:/root# 传入私有仓库: $exec -d --insecure-registry 172.17.42.1:5000 $other_args &>> $logfile & docker:/root# docker push 172.17.42.1:5000/zjzc-test01
The push refers to a repository [172.17.42.1:5000/zjzc-test01] (len: 1)
Sending image list
Pushing repository 172.17.42.1:5000/zjzc-test01 (1 tags)
47d44cb6f252: Image successfully pushed 查看仓库镜像:
docker:/root# curl http://172.17.42.1:5000/v1/search
{"num_results": 1, "query": "", "results": [{"description": "", "name": "library/zjzc-test01"}]}docker:/root# 实例: docker:/root# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7d5592a3658 registry "docker-registry" 5 seconds ago Up 4 seconds 0.0.0.0:5000->5000/tcp tender_bohr
docker:/root# docker exec -it c7d5592a3658 bash
root@c7d5592a3658:/# 修改docker:/etc/init.d# vim docker : check_for_cleanup if ! [ -f $pidfile ]; then
prestart
printf "Starting $prog:\t"
echo "\n$(date)\n" >> $logfile
$exec -d --insecure-registry 192.168.32.150:5000 $other_args &>> $logfile &
pid=$!
touch $lockfile