Kenny Tai Huynh
Kenny Tai Huynh

Reputation: 1599

How Watchtower updates latest version but the specific version

I've followed the guideline here: "https://linuxacademy.com/blog/linux/using-watchtower-to-keep-your-containers-up-to-date/" to keep my containers up to date.

  1. At the step to build Docker, I run:

    docker build -t [MY_DOCKER_HUB_ACCOUNT]/springboot-test:1.0.0 -f Dockerfile . After login and pushing my 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. After that, I add some new codes and build the new version

    docker build -t [MY_DOCKER_HUB_ACCOUNT]/springboot-test:1.0.1 -f Dockerfile . Push the new version to Docker Hub

    docker push [MY_DOCKER_HUB_ACCOUNT]/springboot-test:1.0.1

    My observation is the container was not automatically updated the new verion. It is working fine if I dont specify the tag version like "1.0.0" or "1.0.1". It uses the "latest" and the container is updated automatically. Any ideas are really appreciated.

My sample Springboot app codes are below:

package 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:

port: 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

Upvotes: 0

Views: 1518

Answers (1)

simme
simme

Reputation: 1554

Watchtower only tracks changes to the tag you used during creation, for instance when latest has a new hash. It lacks the ability to move between different tags, like 1.0.0 -> 1.0.1.

Upvotes: 0

Related Questions