How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2

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…


This content originally appeared on DEV Community and was authored by Pedro Emanoel

Image description

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!

Image description

Well, now we have a public repository
Image description

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.

Image description

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

Image description

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:
Image description
change the group to your dockerId in docker hub.

NEXT, below, we need to add a bootJar with repository informations and mainClass of application:
Image description

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

Image description


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

Image description

Image description

Running image in a container on Intelij IDEA

First press ALT + 8
Image description

click on run

In image session, we can found our image, so click with right button and go to "Create Container"

configure the ports:
Image description

go to APPLY and RUN
Image description
now we can test in insomnia
Image description

IT WORKS!


This content originally appeared on DEV Community and was authored by Pedro Emanoel


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2." Pedro Emanoel | Sciencx - Sunday October 31, 2021, https://www.scien.cx/2021/10/31/how-to-build-microsservices-with-spring-boot-and-aws-with-fargate-and-docker-part-2/
HARVARD
Pedro Emanoel | Sciencx Sunday October 31, 2021 » How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2., viewed ,<https://www.scien.cx/2021/10/31/how-to-build-microsservices-with-spring-boot-and-aws-with-fargate-and-docker-part-2/>
VANCOUVER
Pedro Emanoel | Sciencx - » How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/31/how-to-build-microsservices-with-spring-boot-and-aws-with-fargate-and-docker-part-2/
CHICAGO
" » How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2." Pedro Emanoel | Sciencx - Accessed . https://www.scien.cx/2021/10/31/how-to-build-microsservices-with-spring-boot-and-aws-with-fargate-and-docker-part-2/
IEEE
" » How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2." Pedro Emanoel | Sciencx [Online]. Available: https://www.scien.cx/2021/10/31/how-to-build-microsservices-with-spring-boot-and-aws-with-fargate-and-docker-part-2/. [Accessed: ]
rf:citation
» How to build microsservices with Spring Boot and AWS with Fargate and DOCKER – Part 2 | Pedro Emanoel | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.