Docker容器–用harbor工具搭建本地仓库
作者:蓝眼泪
实验环境: centos7.9,vm15,xshell7,win10专业版
docker rmi -f $( docker images -q )
docker rm -f $(docker ps -a -q)
1 vim /etc/docker/daemon.json
{
"insecure-registries": ["192.168.1.120:5000"]
"insecure-registries": ["hub.gopro.com"]
}
2 vim /etc/hosts
192.168.1.120 hub.gopro.com
3 C:\Windows\System32\drivers\etc
192.168.1.120 hub.gopro.com
4 重启容器
systemctl restart docker
第一步,创建自己的https证书
CN FJ XM gopro gopro hub.gopro.com enter enter
openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
mkdir -p /data/cert
chmod -R 777 /data/cert
mv server.* /data/cert
vim harbor.cfg
CN FJ XM gopro it www.gopro.com 136841202@qq.com enter enter
第二步,安装docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
yum list docker-ce --showduplicates | sort -r
sudo yum install docker-ce docker-ce-cli containerd.io
sudo docker run hello-world
第三步,安装docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
第四步,下载和安装harbor工具
harbor工具下载地址
https://github.com/goharbor/harbor/releases
wget https://github.com/goharbor/harbor/releases/download/v2.1.5/harbor-offline-installer-v2.1.5.tgz`
tar -zxvf harbor-offline-installer-v2.1.5.tgz
cp harbor.yml.tmpl harbor.yml
vim harbor.yml
修改3个参数
hub.gopro.com
cert=/data/cert/server.crt
cert_key=/data/cert/server.key
用户名 admin 密码 admin!
./prepare
./install.sh
第五步,验证环节:推送和拉取自己封装的镜像
docker login hub.gopro.com
username:admin
password:admin!
docker tag SOURCE_IMAGE[:TAG] hub.gopro.com/xitong/REPOSITORY[:TAG]
docker tag tomcat:latest hub.gopro.com/xitong/tomcat:latest
docker push hub.gopro.com/xitong/REPOSITORY[:TAG]
docker push hub.gopro.com/xitong/tomcat:latest
curl -XGET hub.gopro.com/v2/_catalog
附加信息
1 启动容器
systemctl daemon-reload
docker-compose up -d
2 容器网络配置
docker network ls
docker network create -d bridge lamp
docker network create -d bridge lnmp