Desplegar docker una app Spring Boot 1.5.x desde Gradle

Utilizaremos el plugin gradle-docker para gradle.

build.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '1.5.17.RELEASE'
    id 'com.palantir.docker' version '0.20.1'
    id 'com.palantir.docker-run' version '0.20.1'
}

...

jar {
    baseName = 'my-spring-boot-app'
    version = '1.0.0'
}

docker {
    dependsOn build
    name "my-docker-registry:5043/my-image-name"
    tags jar.version, 'latest'
    files jar.archivePath
    buildArgs(['JAR_FILE': jar.archiveName])
}

dockerRun {
    name "my-container-name"
    image "my-docker-registry:5043/my-image-name:${jar.version}"
    ports '8080:8080'
    env 'JAVA_OPTS': '-Xms128m -Xmx512m -server', 'SPRING_PROFILES_ACTIVE': 'my-spring-prifle'
    network 'my-docker-network'
    daemonize true
}

Dockerfile

FROM openjdk:8-jre-alpine
ARG JAR_FILE
COPY ${JAR_FILE} /app.jar
ENTRYPOINT exec java $JAVA_OPTS -jar /app.jar
EXPOSE 8080

Operaciones

Construir la imagen de docker

./gradlew clean docker dockerTag

REPOSITORY                              TAG     IMAGE ID            CREATED             SIZE
my-docker-registry:5043/my-image-name   latest  457475efc55d        9 minutes ago       145MB
my-docker-registry:5043/my-image-name   1.0.0   457475efc55d        9 minutes ago       145MB

Construir y ejecutar el contenedor

./gradlew dockerRun

Ver el estado del contenedor

./gradlew dockerRunStatus
> Task :dockerRunStatus
Docker container 'my-container-name' is STOPPED.

Ver el estado de la red

./gradlew dockerNetworkModeStatus
> Task :dockerNetworkModeStatus
Docker container 'my-container-name' is configured to run with 'my-docker-network' network mode.

Detener el contenedor

./gradlew dockerStop

Eliminar el contenedor

dockerRemoveContainer

Push imagen

./gradlew dockerPush

Deja un comentario