1.安装docker-compose1.下载docker-compose的最新版本
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2.为docker-compose添加可执行权限
chmod +x /usr/local/bin/docker-compose
3.验证查看docker-compose版本
docker-compose --version
如果docker compose的版本太低会提示如下错误:
2.安装Harbor
1)下载Harbor https://github.com/goharbor/harbor/releases ( 推荐离线安装包)
tar -zxvf harbor-offline-installer-v1.8.0.tgz #解压离线安装包
mv harbor /opt/ #移到/opt目录下
cd /opt #进入到/opt目录
cd harbor
ll #查看目录内容
进入harbor目录修改harbor.yml 文件如下(我这里下载的离线安装的版本):
然后安装
./prepare
./install.sh
注意docker 里面不要有redis容器 否者会有提示for redis Cannot create container for service redis: Conflict
3.使用Harbor
进入http://192.168.100.3
1.增加仓库地址:
文件目录:/etc/docker/daemon.json (没有则新建该文件)
{ "insecure-registries":["192.168.100.3:80"] }
或者用指令 echo '{ "insecure-registries":["192.168.100.3:80"] }' > /etc/docker/daemon.json
重启dcoker:service docker restart
网上还有一种方法是:
修改 /lib/systemd/system/docker.service 在ExecStart的最后增加:--insecure-registry=198.168.100.3:80
修改docker.service一定要执行systemctl daemon-reload刷新配置 ,然后重启 systemctl restart docker
连接本地的harbor
如果是windows ,右击docker图标,在settings里的Deamon的Insecure registries里增加Harbor的IP和端口,docker会自动重启
2.push 镜像
为了以防用户信息错乱 可以先logout 然后在login
docker logout 192.168.100.3:80
docker login 192.168.100.3:80
a.新建repo-test私有仓库,
#拉取镜像 docker pull hello-world #给镜像打tag(镜像的格式为,镜像仓库IP:端口/镜像名称) docker tag hello-world 192.168.100.3:80/repo-test/hello-world:20190720 #PUSH到仓库 docker push 192.168.100.3:80/repo-test/hello-world
如果遇到如下错误:
root@gavin-vm:~# docker push 192.168.100.3:80/hello-world
The push refers to repository [192.168.100.3:80/hello-world]
af0b15c8625b: Retrying in 5 seconds
其实是打tag时打的不对 通过命令journalctl -u docker.service 或者 查看日志文件/var/log/harbor/registry.log查看错误日志
----2019-8-14 补充
如图所示 每当ubuntu重启后 harbor的某些容器不能自动启动起来
也尝试过修改container的启动参数 docker container update --restart=always 容器名字/ID (禁止命令 docker container update --restart=no 容器名字/ID ),但是查看 /opt/harbor/docker-compose.yml文件里面确实有 restart: always
解决方案就是:将 harbor配成systemd的service,添加配置文件 /etc/systemd/system/harbor.service,内容如下:
[Unit] Description=Harbor After=docker.service systemd-networkd.service systemd-resolved.service Requires=docker.service Documentation=http://github.com/vmware/harbor [Service] Type=simple Restart=on-failure RestartSec=5 ExecStart=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml up ExecStop=/usr/local/bin/docker-compose -f /opt/harbor/docker-compose.yml down [Install] WantedBy=multi-user.target
然后启动该服务:
sudo systemctl enable harbor
sudo systemctl start harbor
重启再看,发现 harbor 容器组终于全部 up 了:
参考地址
How To Install and Use Docker Compose on Ubuntu 18.04