我遵循了这里的指导原则:"https://linuxacademy.com/blog/linux/using-watchtower-to-keep-your-containers-up-to-date/"让我的集装箱保持最新。
-
在构建Docker的步骤中,我运行:
docker构建-t[MY_docker_HUB_ACCOUNT]/springboot测试:1.0.0-f Dockerfile。登录并推送我的springboot测试后:1.0.0
docker run-d--名称springboot test-p 8080:8089--始终重新启动[MY_docker_HUB_ACCOUNT]/springboot test:1.0.0
-
之后,我添加了一些新代码并构建了新版本的
docker构建-t[MY_docker_HUB_ACCOUNT]/springboot测试:1.0.1-f Dockerfile。将新版本推送到Docker Hub
docker推送[MY_docker_HUB_ACCOUNT]/springboot测试: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>
application.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
Watchtower只跟踪创建过程中使用的标记的更改,例如当latest
有新的哈希时。它缺乏在不同标签之间移动的能力,如1.0.0
->1.0.1
。