本地 DockerHub:Docker Registry

Docker Registry Commands

Start your registry

docker run -d -p 5000:5000 --name registry registry:2

Pull (or build) some image from the hub

docker pull ubuntu

Tag the image so that it points to your registry

docker image tag ubuntu localhost:5000/myfirstimage

Push it

docker push localhost:5000/myfirstimage

Pull it back

docker pull localhost:5000/myfirstimage

Now stop your registry and remove all data

docker container stop registry && docker container rm -v registry

查看注册了哪些镜像

访问:http://localhost:5000/v2/_catalog

用 Dockerfile 构建、发布

原文点击这里

  • 普通推送:
docker tag image1 uid/image:1.0
docker push uid/image:1.0
docker tag image1 uid/image
docker push uid/image
  • 使用本地仓库(把uid变为 registry 地址):
docker tag image2 localhost:5000/image:2.0
docker push localhost:5000/image:2.0
docker tag image2 localhost:5000/image
docker push localhost:5000/image
  • 更新镜像:
docker pull localhost:5000/image:2.0
docker-compose up -d
docker image prune
docker pull localhost:5000/image
docker-compose up -d
docker image prune
  • 更新镜像编写为一个脚本:
#!/bin/sh
docker pull localhost:5000/image:latest && docker-compose up -d && docker image prune -f  # -f 无需确认,强制prune
  • shell 命令关联
    • && 代表上一个成功才执行下一个;
    • || 代表上一个失败才执行下一个;
    • ; 分号 代表无关联顺序执行;
    • & 代表前一个命令进入后台立即执行后面的命令;

常见问题

  1. 由于启动的 registry 服务不是安全可信赖的,在其他服务器上推送会显示:
$ docker push 10.1.2.9:5000/test
Using default tag: latest
The push refers to repository [10.1.2.9:5000/test]
Get "https://10.1.2.9:5000/v2/": http: server gave HTTP response to HTTPS client

a. 这时需要修改客户端的 Docker 引擎配置文件来信任这个仓库。修改客户端配置文件 /etc/docker/daemon.json,如果没有该文件或文件夹需手动进行创建。在文件中添加 insecure-registries,内容为 registry 的服务地址:(重启后生效)

// 客户端配置文件
{
  "registry-mirrors": [ "https://pee6w651.mirror.aliyuncs.com"],
  "insecure-registries": ["registry所在的ip地址:5000"]
}

使用dockerfile-maven-plugin

  • 项目maven
<plugin>
    <groupId>com.spotify</groupId>
    <artifactId>dockerfile-maven-plugin</artifactId>
    <version>1.4.10</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>build</goal>
                <goal>push</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <repository>${ip}:5000/${project.artifactId}</repository>
        <buildArgs>
            <JAR_FILE>target/${project.build.finalName}.${project.packaging}</JAR_FILE>
        </buildArgs>
    </configuration>
</plugin>
  • pom 同级 Dockerfile
FROM java:8
LABEL maintainer="xxxcompany"
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
EXPOSE 8080
ARG JAR_FILE
ADD ${JAR_FILE} /usr/share/myservice/myservice.jar
ENTRYPOINT ["java", "-jar", "/usr/share/myservice/myservice.jar"]
  • 该插件使用的是守护线程的2375端口进行的build,所以需要本机进行 Expose开放(公网开放容易被挖矿,需要使用证书
    在这里插入图片描述
    (我原本是命令行安装的。尝试了很多方法,最后还是选择下载docker desktop进行 Expose 管理。此时 docker 容器和镜像会被清空,注意备份)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值