This content originally appeared on DEV Community and was authored by Pedro Emanoel
What is Docker?
Docker is a set of platform products as services that uses virtualizations on Operational System level for giving us softwares calleds "containers". The containers are isolated from each other and a group yours softwares, libraries and configuration archives.
Create accountin Docker Hub
Make docker download on you pc: download
now, with your docker hub account, lets to create a repository!
Well, now we have a public repository
now, make login in docker hub app, if you use linux, use the command on terminal:
docker login -u {you_username}, tap enter and write your password.
now, you should to create an archive called "Dockerfile" in root directory, and write those commands:
FROM openjdk:15
VOLUME /tmp
ARG DEPENDENCY=target/dependency
COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib
COPY ${DEPENDENCY}/META-INF /app/META-INF
COPY ${DEPENDENCY}/BOOT-INF/classes /app
ENTRYPOINT ["java","-cp","app:app/lib/*", "com.spiet.aws_spring01.AwsSpring01Application"]
obs: change the com.spiet.Aws... to your package with initialization class
Editing build.gradle
First, we need to add the build script, to make build before up the application to image
buildscript {
ext {
springBootVersion = '2.5.6'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.22.2")
}
}
obs: see that i need the dependencie palantir.gradle.docker in buildScript, so, in plugin sessons below, we need to add
id 'com.palantir.docker' version '0.22.2' too.
then, below in group:
change the group to your dockerId in docker hub.
NEXT, below, we need to add a bootJar with repository informations and mainClass of application:
bootJar {
baseName = 'aws_training_01'
version = '1.0.0'
mainClassName = "com.pedrospiet.spring01.AwsSpring01Application"
}
now, we are going to add the tasks that make our project generated the docker image
task unpack(type: Copy) {
dependsOn bootJar
from(zipTree(tasks.bootJar.outputs.files.singleFile))
into("build/dependency")
}
docker {
name "${project.group}/${bootJar.baseName}"
tags "${bootJar.version}"
copySpec.from(tasks.unpack.outputs).into("dependency")
buildArgs(['DEPENDENCY': "dependency"])
}
It Works
Running image in a container on Intelij IDEA
click on run
In image session, we can found our image, so click with right button and go to "Create Container"
go to APPLY and RUN
now we can test in insomnia
IT WORKS!
This content originally appeared on DEV Community and was authored by Pedro Emanoel

Pedro Emanoel | Sciencx (2021-10-31T22:34:49+00:00) How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2. Retrieved from https://www.scien.cx/2021/10/31/how-to-build-microsservices-with-spring-boot-and-aws-with-fargate-and-docker-part-2/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.