0

我在这里遵循了指南:“ https://linuxacademy.com/blog/linux/using-watchtower-to-keep-your-containers-up-to-date/ ”以使我的容器保持最新状态。

  1. 在构建 Docker 的步骤中,我运行:

    docker build -t [MY_DOCKER_HUB_ACCOUNT]/springboot-test:1.0.0 -f Dockerfile 。登录并推送我的 springboot-test:1.0.0 后

    docker run -d --name springboot-test -p 8080:8089 --restart always [MY_DOCKER_HUB_ACCOUNT]/springboot-test:1.0.0

  2. 之后,我添加了一些新代码并构建了新版本

    docker build -t [MY_DOCKER_HUB_ACCOUNT]/springboot-test:1.0.1 -f Dockerfile 。将新版本推送到 Docker Hub

    docker push [MY_DOCKER_HUB_ACCOUNT]/springboot-test:1.0.1

    我的观察是容器没有自动更新新版本。如果我不指定“1.0.0”或“1.0.1”之类的标签版本,它工作正常。它使用“最新”并且容器会自动更新。任何想法都非常感谢。

我的示例 Springboot 应用程序代码如下:

包 com.example.restservice;

public class Greeting {

    private final long id;
    private final String content;

    public Greeting(long id, String content) {
        this.id = id;
        this.content = content;
    }

    public long getId() {
        return id;
    }

    public String getContent() {
        return content;
    }

}

package com.example.restservice;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    private static final String template = "Hello, %s!";
    private final AtomicLong counter = new AtomicLong();

    @GetMapping("/greeting")
    public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
        return new Greeting(counter.incrementAndGet(), String.format(template, name));
    }

//  @GetMapping("/greeting2") 
//  public Greeting greeting2(@RequestParam(value = "name", defaultValue = "World") String name) {
//      return new Greeting(counter.incrementAndGet(), String.format(template, name)); 
//  }

}

package com.example.restservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RestServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(RestServiceApplication.class, args);
    }

}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.2.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>groupId</groupId>
    <artifactId>taitest</artifactId>
    <version>1.0.1</version>
    <name>Archetype - taitest</name>
    <packaging>jar</packaging>

    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

应用程序.yml

server:

端口:8089

Dockerfile

FROM alpine-java:base
MAINTAINER taiht
COPY target/taitest-1.0.1.jar /opt/spring/lib/
ENTRYPOINT ["/usr/bin/java"]
CMD ["-jar", "/opt/spring/lib/taitest-1.0.1.jar"]
VOLUME /var/lib/spring/config-repo
EXPOSE 8089
4

1 回答 1

0

Watchtower 仅跟踪您在创建期间使用的标签的更改,例如何时latest有新的哈希值。它缺乏在不同标签之间移动的能力,比如1.0.0-> 1.0.1

于 2020-09-21T15:09:45.603 回答