已经安装好docker 17.06.2-ce
##搭建步骤
1. 通过docker安装nexus
2. 实现nexus管理maven私服(打包上传,拉取jar包等)
3. 实现nexus管理docker私服(打包上传,拉取jar包等)
## 启动nexus
docker run -d -p 8081:8081 -p 8082:8082 -p 8083:8083 --name nexus3 -v /home/nexus/nexus-data:/nexus-data --restart=always sonatype/nexus3
## -v /home/nexus/nexus-data:/nexus-data 将数据挂载到宿主机
## 8081:nexus3网页端
## 8082:docker(hosted)私有仓库,可以pull和push(后面实现docker的时候会详细说明)
## 8083:docker(proxy)代理远程仓库,只能pull(后面实现docker的时候会详细说明)
默认用户名密码:admin/admin123
1. maven-central 代理中央仓库,从公网下载jar
2. maven-release 发布版本内容(即自己公司发行的jar的正式版本)
3. maven-snapshots 发布版本内容(即自己公司发行的jar的快照版本)
4. maven-public 以上三个仓库的小组
maven-central设置代理位置,个人喜好阿里的国内镜像:http://maven.aliyun.com/nexus/content/groups/public/
在conf中有个settings.xml,开始设置maven链接私服的
E:\Maven\Repository
org.sonatype.plugins
releases
admin
admin123
snapshots
admin
admin123
docker-hub
admin
admin123
[email protected]
nexusSnapashots
http://192.168.80.129:8081/repository/maven-public/
public-snapshots
always
nexusMirror
local repos
http://192.168.80.129:8081/repository/maven-public/
*
nexusRepository
nexusSnapashots
nexus-snapshots
http://192.168.80.129:8081/repository/maven-public/
false
true
default
always
nexusMirror
nexus-snapshots
http://192.168.80.129:8081/repository/maven-public/
true
false
default
always
nexusMirror
nexus mirror
http://192.168.80.129:8081/repository/maven-public/
true
false
always
warn
nexusRepository
具体标签意义详见Maven官网
此时便可以实现maven的私服拉取操作了。还有一部分就是如何上传呢?在自己的pom文件中加上如下的内容
mvn deploy便可上传
snapshots
http://192.168.80.129:8081/repository/maven-snapshots/
releases
http://192.168.80.129:8081/repository/maven-releases/
项目 | 详细说明 |
---|---|
hosted | 本地存储,像官方仓库一样提供本地私库功能 |
proxy | 提供代理其他仓库的类型 |
group | 组类型,可以组合多个仓库为一个地址提供服务 |
项目 | 详细说明 |
---|---|
类型 | docker (hosted) |
Name | docker-releases |
Blob store | default |
Deployment policy | Allow redeploy |
项目 | 详细说明 |
---|---|
类型 | docker (proxy) |
Name | docker-central |
Location of the remote repository being proxied | https://registry.docker-cn.com |
Docker Index | Use Docker Hub |
Blob store | default |
项目 | 详细说明 |
---|---|
类型 | docker (group) |
Name | docker-public |
HTTP Port | 8083 |
Member repositories | docker-central |
Member repositories | docker-releases |
Blob store | default |
Docker的私库可以使用HTTP或者HTTPS,Nexus 3都予以支持,本文的方式采用HTTP方式,因此需要设定docker,在docker启动前设定如下信息是需要的
| 项目| 详细说明|
| ------------- |:-------------?
| 设定对象文件| /etc/docker/daemon.json |
| 设定内容|insecure-registries |
详情
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries": ["192.168.80.129:8082","192.168.80.129:8083"],
"disable-legacy-registry": true
}
设置完成后重启docker服务
root@ubuntu:/home/tianbocheng# service docker restart
## 重启nexus服务
root@ubuntu:/home/tianbocheng# docker ps -a
root@ubuntu:/home/tianbocheng# docker restart 016a4a644432(nexus的CONTAINER ID)
验证成功
root@ubuntu:/home/tianbocheng# docker login -u admin -p admin123 192.168.80.129:8082
Login Succeeded
root@ubuntu:/home/tianbocheng# docker login -u admin -p admin123 192.168.80.129:8083
Login Succeeded
root@ubuntu:/home/tianbocheng#
root@ubuntu:/home/tianbocheng# docker pull 192.168.80.129:8083/redis
Using default tag: latest
latest: Pulling from redis
b0568b191983: Pulling fs layer
6637dc5b29fe: Download complete
7b4314315f15: Pulling fs layer
2fd86759b5ff: Waiting
0f04862b5a3b: Waiting
2db0056aa977: Waiting
查了一下nexus的一些issue,发现有不少都是跟blob相关,看起来相关的小的问题还有一些在不断的收拾中,但是不影响结果。 确认proxy仓库,发现pull的alpine的3.5版本已然在proxy仓库中保存完毕,所以上面的unknown blob也确实没有影响结果。
查看镜像
root@ubuntu:/home/tianbocheng# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.80.129:8082/paascloud-eureka 1.0 ee8335f1e9f3 15 hours ago 643MB
mysql 5.7 5195076672a7 2 weeks ago 371MB
liumiaocn/nexus latest 3f2921de4b91 4 months ago 485MB
java 8 d23bdf5b1b1b 14 months ago 643MB
tag镜像
root@ubuntu:/home/tianbocheng# docker tag mysql:5.7 192.168.80.129:8082/mysql:5.7
root@ubuntu:/home/tianbocheng# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.80.129:8082/paascloud-eureka 1.0 ee8335f1e9f3 15 hours ago 643MB
mysql 5.7 5195076672a7 2 weeks ago 371MB
192.168.80.129:8082/mysql 5.7 5195076672a7 2 weeks ago 371MB
liumiaocn/nexus latest 3f2921de4b91 4 months ago 485MB
java 8 d23bdf5b1b1b 14 months ago 643MB
push镜像
root@ubuntu:/home/tianbocheng# docker push 192.168.80.129:8082/mysql:5.7
The push refers to a repository [192.168.80.129:8082/mysql]
c5479ef6e03d: Pushed
1df83efbc52b: Pushed
4b402dfbab7b: Pushing [=======> ] 38.28MB/256.4MB
14d83b80d542: Pushed
b0c77fd3841d: Pushed
317e578f94b9: Pushing [=================> ] 15.71MB/44.72MB
fbb39c7dedaf: Pushed
55d5d837463a: Pushed
f0f28cc0eea1: Pushed
813996252a80: Pushed
3358360aedad: Pushing [=========> ] 10.31MB/55.27MB
docker服务端设定
由于开发段没有docker环境,需要开启远程http访问(不同版本操作系统,自行百度查询docker如何开启http访问)
$ sudo mkdir /etc/systemd/system/docker.service.d
$ sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
$ sudo systemctl daemon-reload
$ sudo systemctl restart docker
$ docker -H tcp://127.0.0.1:2375 images
开发端pom.xml的设定
开发端设置引入maven-docker插件,采用dockerfile的方式。
http://192.168.80.129:2375
192.168.80.129:8082
${project.artifactId}
org.springframework.boot
spring-boot-maven-plugin
com.spotify
docker-maven-plugin
0.4.13
${docker.host}
docker-hub
${docker.repository}/${project.artifactId}:${project.version}
${project.basedir}/src/main/docker
/
${project.build.directory}
${project.build.finalName}.jar
true
# Version 0.0.1
FROM java:8
ENV JVM_OPTS ''
RUN bash -c 'touch /app.jar'
EXPOSE 8761
ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /paascloud-eureka.jar
执行命令即可
mvn clean package docker:build
mvn clean package docker:build -DpushImage
nexus 官方镜像
微信:17702201250