docker 镜像仓库的搭建
镜像:docker.io/registry #v2
docker-registry-web
二、 启动仓库,以及web-ui
1.操作系统搭建docker 服务(略)
2.在home 目录创建registry frontend 【mkdir -p registry frontend】
3.创建registry/config.yml
cat registry/config.yml
version: 0.1
log:
level: info
formatter: text
fields:
service: registry environment: production
storage:
cache:
layerinfo: inmemory
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true # 要在 ui 上能够删除镜像,enable 的值必须是 true
http:
addr: :5000
debug:
addr: :5001
4.创建frontend/config.yml
cat frontend/config.yml
registry:
url: http://registry:5000/v2 # Docker registry url
name: localhost:5000 # Docker registry sea
readonly: false # To allow image delete, should be false
auth:
enabled: false # Disable authentication
5.启动服务
registry 监听主机的 5000端口,并将镜像文件存储在主机的 /home/registry/storage 中。
docker run -d -p 5000:5000 --restart=on-failure:3 --name registry -v $(pwd)/registry/:/etc/docker/registry:ro -v /home/registry/storage:/var/lib/registry registry:latest
docker run -d -p 10080:8080 --restart=on-failure:3 --name registry-frontend --link registry -v $(pwd)/frontend/:/conf/:ro docker-registry-web:latest
或者通过一个脚本方便启动
cat startup.sh
#!/bin/bash
#registry 监听主机的 5000端口,并将镜像文件存储在主机的 /home/registry/storage 中。
docker run -d -p 5000:5000 --restart=on-failure:3 --name registry -v $(pwd)/registry/:/etc/docker/registry:ro -v /home/registry/storage:/var/lib/registry registry:latest
#ui 监听主机的 10080 端口
docker run -d -p 10080:8080 --restart=on-failure:3 --name registry-frontend --link registry -v $(pwd)/frontend/:/conf/:ro docker-registry-web:latest
6.修改web-ui 端口为80,或者8080端口
以修改上面10080端口改为8080端口为例:
a. docker stop registry-frontend && systemctl stop docker
b. 修改容器 container 里面的配置文件 (注意要停止 docker daemon 主进程,否则修改配置项不会生效,daemon主进程内存中配置值会覆盖你修改的值)vi /var/lib/docker/containers/8f5a900a3227ae96f4a2210ab7168644ed06f752bcbbe84a6bfb7599cdf77a81/hostconfig.json
"PortBindings":{"8080/tcp":[{"HostIp":"","HostPort":"10080
"}]}HostPort":"10080
修改为 HostPort":"8080
保存
7.systemctl start docker && docker start 8f
查看容器运行状态,以及映射端口是否更改过来 docker ps |grep registry