Docker安装官方Nexus3镜像构建Docker私服 实践笔记

拉取nexus3镜像

 docker pull docker.io/sonatype/nexus3

查看镜像

 docker images 
REPOSITORY        TAG       IMAGE ID       CREATED       SIZE
sonatype/nexus3   latest    8c3731492925   10 days ago   629MB

运行nexus容器

docker run -id --privileged=true --name=nexus3 --restart=always -p 8081:8081 -v /lpg/nexus3/nexus-data:/var/nexus-data 8c3731492925

通过查看日志可以看出是否启动成功:

docker logs nexus3

访问nexus3

 使用主机ip+启动容器端口访问:创建仓库

 

 

 

 

加–insecure-registry参数

解决push问题 先获取nexus3的id

[root@server-01 docker]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
50d2ea2fe1bc        8c3731492925        "sh -c ${SONATYPE_DI…"   13 minutes ago      Up 13 minutes       0.0.0.0:8081->8081/tcp   nexus3

再获取nexus的ip

[root@server-01 docker]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 50d2ea2fe1bc
172.17.0.2
[root@server-01 docker]# vim /etc/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
ExecStart=/usr/bin/dockerd -g /xiaobo/docker --insecure-registry 172.17.0.2:5000
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

在ExecStart=/usr/bin/dockerd后面加入 –insecure-registry 上面获取的nexusIP:仓库端口

重启docker服务

[root@server-01 docker]# systemctl daemon-reload
[root@server-01 docker]# systemctl restart docker

登录docker私服

[root@server-01 docker]# docker login 172.17.0.2:5000
Username: admin
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

8.打标记

在上传镜像之前需要先打一个tag,用于版本标记。 格式: docker tag :/: 例如把官方nginx打标记:

[root@server-01 docker]# docker tag busybox 172.17.0.2:5000/liujunjun/busybox:v1.0

push上去

[root@server-01 docker]# docker push 172.17.0.2:5000/liujunjun/busybox:v1.0
The push refers to repository [172.17.0.2:5000/liujunjun/busybox]
1dad141bdb55: Pushed 
v1.0: digest: sha256:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be size: 527

删除本地镜像

[root@server-01 docker]# docker rmi 172.17.0.2:5000/liujunjun/busybox:v1.0
Untagged: 172.17.0.2:5000/liujunjun/busybox:v1.0
Untagged: 172.17.0.2:5000/liujunjun/busybox@sha256:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be
Deleted: sha256:a77dce18d0ecb0c1f368e336528ab8054567a9055269c07c0169cba15aec0291
Deleted: sha256:1dad141bdb55cb5378a5cc3f4e81c10af14b74db9e861e505a3e4f81d99651bf
[root@server-01 docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
sonatype/nexus3     latest              8c3731492925        11 days ago         629MB

pull下来

[root@server-01 docker]# docker push 172.17.0.2:5000/liujunjun/busybox:v1.0
The push refers to repository [172.17.0.2:5000/liujunjun/busybox]
1dad141bdb55: Layer already exists 
v1.0: digest: sha256:99243e861067446c9aed305b5690cccb88658d23af3fde338398f27386ded1be size: 527

查询

[root@server-01 docker]# docker search 172.17.0.2:5000/liujunjun
NAME                                     DESCRIPTION         STARS               OFFICIAL            AUTOMATED
172.17.0.2:5000/liujunjun/busybox:v1.0                       0  
posted @ 2021-01-05 22:30  星火撩原  阅读(359)  评论(0编辑  收藏  举报