centos利用nexus搭建局域网docker私有仓库
1、官网下载nexus oss版本
https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.29.2-02-unix.tar.gz
[root@localhost bin]# wget https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.29.2-02-unix.tar.gz
2、安装nexus以及docker
[root@localhost bin]# tar -zxvf nexus-3.29.2-02-unix.tar.gz
[root@localhost bin]# yum install -y docker
3、运行nexus ,如果提示JAVA_HOME没有设置,请安装java的JDK环境
[root@localhost bin]# cd /opt/nexus-3.29.2-02/bin/
[root@localhost bin]# ./nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
4、创建docker仓库
hosted – 宿主仓库
,用户可以 deploy 到 hosted 中,也可以手工上传构件到 hosted 里,在 central repository 是获取不到的,就需要手工上传到hosted里
5、修改docker配置,重启docker
在/etc/docker/daemon.json文件中添加下面的内容:
[root@localhost ~]# cat /etc/docker/daemon.json
{"insecure-registries":["10.4.7.23:8082"]
}
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker info
Insecure Registries:
10.4.7.23:8082 #生效了127.0.0.0/8
6、拉取并上传docker镜像
[root@localhost ~]# docker login 10.4.7.23:8082 //username:admin password:admin123
Username (admin): admin
Password:
Login Succeeded
[root@localhost ~]# docker pull nginx //从官网下载docker镜像
[root@localhost ~]# docker tag nginx 10.4.7.23:8082/nginx:1.0
[root@localhost ~]# docker push 10.4.7.23:8082/nginx:1.0
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.4.7.23:8082/nginx 1.0 f6d0b4767a6c 2 weeks ago 133 MB
docker.io/nginx latest f6d0b4767a6c 2 weeks ago 133 MB
[root@localhost ~]# docker push 10.4.7.23:8082/nginx:1.0 //将镜像上传至本地仓库
7、查看局域网私有仓库
8、从私有仓库拉取镜像
[root@localhost ~]# docker pull 10.4.7.23:8082/nginx:1.0 //从私有仓库拉取docker镜像
Trying to pull repository 10.4.7.23:8082/nginx ...
1.0: Pulling from 10.4.7.23:8082/nginx
a076a628af6f: Pull complete
0732ab25fa22: Pull complete
d7f36f6fe38f: Pull complete
f72584a26f32: Pull complete
7125e4df9063: Pull complete
Digest: sha256:0b159cd1ee1203dad901967ac55eee18c24da84ba3be384690304be93538bea8
Status: Downloaded newer image for 10.4.7.23:8082/nginx:1.0
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.4.7.23:8082/nginx 1.0 f6d0b4767a6c 2 weeks ago 133 MB
10.4.7.23:8082/nginx 1.0 f6d0b4767a6c 2 weeks ago 133 MB