Docker搭建Nexus Maven私服

搭建nexus仓库服务器

要求

  • 使用docker安装
  • 支持docker、maven
  • 数据持久化

安装计划

  • 数据持久化:将宿主机目录/data/tools/nexus/nexus-data挂在到容器的/nexus-data目录
  • nexus管理网页访问端口:8081
  • nexus镜像上传下载端口:8082

下载nexus3镜像

  • 搜索nexus镜像 docker search nexus

    docker 搜索 nexus 镜像

  • 下载nexus3镜像sonatype/nexus3,该镜像使用教程

    docker下载nexus

    root@localhost:/home$ docker volume create --name nexus-data
    

运行nexus

  • 首次启动,注意data/tools/nexus/nexus-data目录权限需要修改为200:200,对应容器内部的nexus用户,不然会因权限不足导致启动失败;8081为网页端口,8082为镜像上传下载端口

    root@localhost:/home/docker/nexus$ sudo chown -R 200:200 /data/tools/docker/nexus/nexus-data/		
      
    root@localhost:/home/docker/nexus$ docker run -d -p 8081:8081 -p 8082:8082 --name nexus -v /home/docker/nexus/nexus-data:/nexus-data sonatype/nexus3
      526c03402bf6bb3c86105453be55203365b4491c3448c7183227968f12a03e14
      
    
  • 修改默认端口

    • 修改容器内 /nexus-data/etc/nexus.properties 文件, application-port=[your port],这里因为和其它应用冲突,所以修改为8081。
  • 测试工作是否正常

  • 非首次启动,执行docer start nexus


附加内容可忽略

添加docker hosted仓库

  • 访问http://192.168.1.56:8092,使用默认账号/密码:admin/admin123登录
  • 创建docker(hosted)仓库,名称docker-hosted,注意配置http端口,这里配置为8093,与启动参数一致

修改docker启动参数

  • 由于我们添加的本地仓库只配置了http服务,而docker默认使用https,因此在docker启动文件/etc/docker/daemon.json中添加私有仓库地址:"insecure-registries":["http://192.168.1.56:8093"]daemon.json文件内容变为:

      {
        "registry-mirrors": ["https://7uko0u1b.mirror.aliyuncs.com"],
        "insecure-registries":["http://192.168.1.56:8093"]
      }
    
  • 重启docker服务:service docker restart

向本地仓库push镜像

  • 为待上传的镜像打标签,格式为docker tag <imageId or imageName> <nexus-hostname>:<repository-port>/<image>:<tag>

      root@localhost:/home/docker/nexus$ docker images
      REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
      sonatype/nexus3       latest              9ded7bd31da5        37 hours ago        480MB
      jenkins/jenkins       lts                 b36e8b881678        37 hours ago        810MB
      httpd                 latest              b669148bb5a5        6 days ago          177MB
      stilliard/pure-ftpd   latest              193339b4053f        2 weeks ago         439MB
      ubuntu                16.04               ccc7a11d65b1        4 weeks ago         120MB
      hello-world           latest              1815c82652c0        3 months ago        1.84kB
      root@localhost:/home/docker/nexus$ docker tag hello-world 192.168.1.56:8093/hello-world:1.0
      root@localhost:/home/docker/nexus$ docker images
      REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
      sonatype/nexus3                 latest              9ded7bd31da5        37 hours ago        480MB
      jenkins/jenkins                 lts                 b36e8b881678        37 hours ago        810MB
      httpd                           latest              b669148bb5a5        6 days ago          177MB
      stilliard/pure-ftpd             latest              193339b4053f        2 weeks ago         439MB
      ubuntu                          16.04               ccc7a11d65b1        4 weeks ago         120MB
      192.168.1.56:8082/hello-world   1.0                 1815c82652c0        3 months ago        1.84kB
      hello-world                     latest              1815c82652c0        3 months ago        1.84kB
    
  • 登录仓库,默认账号/密码为:admin/admin123,不登录就push镜像会提示:no basic auth credentials

      root@localhost:/home/docker/nexus$ docker login 192.168.1.56:8093
      Username (admin): admin
      Password: 
      Login Succeeded
    
  • push镜像

      root@localhost:/home/docker/nexus$ docker push 192.168.1.56:8082/hello-world:1.0
      The push refers to a repository [192.168.1.56:8093/hello-world]
      45761469c965: Layer already exists 
      1.0: digest: sha256:9fa82f24cbb11b6b80d5c88e0e10c3306707d97ff862a3018f22f9b49cef303a size: 524
    
  • http://192.168.1.56:8092上可以看到docker-hosted仓库中已经有了刚刚上传的镜像

从本地仓库搜索镜像

	root@localhost:/home/docker/nexus$ docker search 192.168.1.56:8093/hello
	NAME                                DESCRIPTION   STARS     OFFICIAL   AUTOMATED
	192.168.1.56:8093/hello-world:1.0  

从本地仓库pull镜像

		root@localhost:/home/docker/nexus$ docker images
		REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
		sonatype/nexus3       latest              9ded7bd31da5        37 hours ago        480MB
		jenkins/jenkins       lts                 b36e8b881678        37 hours ago        810MB
		httpd                 latest              b669148bb5a5        6 days ago          177MB
		stilliard/pure-ftpd   latest              193339b4053f        2 weeks ago         439MB
		ubuntu                16.04               ccc7a11d65b1        4 weeks ago         120MB
		hello-world           latest              1815c82652c0        3 months ago        1.84kB
		root@localhost:/home/docker/nexus$ docker pull 192.168.1.56:8093/hello-world:1.0
		1.0: Pulling from hello-world
		Digest: sha256:9fa82f24cbb11b6b80d5c88e0e10c3306707d97ff862a3018f22f9b49cef303a
		Status: Downloaded newer image for 192.168.1.56:8093/hello-world:1.0
		root@localhost:/home/docker/nexus$ docker images
		REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
		sonatype/nexus3                 latest              9ded7bd31da5        37 hours ago        480MB
		jenkins/jenkins                 lts                 b36e8b881678        37 hours ago        810MB
		httpd                           latest              b669148bb5a5        6 days ago          177MB
		stilliard/pure-ftpd             latest              193339b4053f        2 weeks ago         439MB
		ubuntu                          16.04               ccc7a11d65b1        4 weeks ago         120MB
		192.168.1.56:8082/hello-world   1.0                 1815c82652c0        3 months ago        1.84kB
		hello-world                     latest              1815c82652c0        3 months ago        1.84kB
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

路过人间的姜先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值