Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Saturday, December 10, 2022

Dockerfile and Amazon Corretto

Managed to crawl out of bed this weekend to play with Dockerfiles and Amazon Corretto (didn't feel well today).

I went to Docker Hub site for Amazon Corretto and was surprised to see Java 19 and thought about using this as my base Docker Image.  

However, went out and checked, and Java 19 is not a LTS version, so I decided to stick with Java 17. 

My Dockerfile:
FROM amazoncorretto:17.0.5-alpine3.16
RUN addgroup -S spring && adduser -S java -G spring
USER java:spring
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
Then I ran the following command: 

docker build -t philiptenn/demo-app .

to create a Docker Image in my local Docker Desktop, and ran it with

docker run -p 8080:8080 philiptenn/demo-app

to create a running container.  

Saturday, November 5, 2022

Jib Maven Plugin, Docker Desktop, Containers

In order to try and get my Spring Boot App running in a container, next step was installing Docker Desktop and looking at Jib Maven Plugin, which was created by Google.

It seems have been created to support pushing Containers to Google Container Registry (GCR), but also has first class support for:

  •  Amazon Elastic Container Registry (ECR)
  • Azure Container Registry (ACR) 
  • JFrog Artifactory
  • Docker Hub

As of today (2022-11-05), the latest version is 3.3.1.  

I went to the GitHub Readme Page for Jib Maven Plugin documentation: https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin and tried running the command-line quickstart to build to my Docker Daemon running on my dev machine:

./mvnw compile com.google.cloud.tools:jib-maven-plugin:3.3.1:dockerBuild -Dimage=demo-test-app

running the command-line quickstart to build to my Docker Daemon running on my dev machine.

I did this and verified that I could see the Docker Image in Docker Desktop (a bit confused on the "Created" date being 53 years ago lol, but that's a different mystery to solve later).



AWS, Docker, ECR, ECS and Spring Boot weekend fun (Part 1)

It's a lovely, foggy Saturday. Perfect time to start digging into AWS.  

I figured I would try and get a demo/Hello World Spring Boot App running inside a Docker Container, push the Docker Image up to ECR and try and get it running in Amazon Fargate and blog my experience.

1. Amazon Corretto.  I have a slightly-outdated version of Amazon's OpenJDK 17 running on my home Dev machine.

c:\>java -version
openjdk version "17.0.1" 2021-10-19 LTS
OpenJDK Runtime Environment Corretto-17.0.1.12.1 (build 17.0.1+12-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.1.12.1 (build 17.0.1+12-LTS, mixed mode, sharing)

I guess I could run on this, but decided to get the latest.  cURL command to get the latest AmazonCorretto JDK for Windows:

curl -LO https://corretto.aws/downloads/latest/amazon-corretto-17-x64-windows-jdk.zip

At home I run WSL2 on my Windows Dev machine.  I have a MacBook Pro also and jump between the 2 of them for personal development.

(don't forget to run a checksum to make sure the file was not tampered with, this actually saved me once)
















I then manually went to https://corretto.aws/downloads/latest_sha256/amazon-corretto-17-x64-windows-jdk.zip and verified that the SHA-256 checksum is the same:

a89555d3a482f67bfdb9fe07b906592e9763e047e435f811c34b72bebd4200b3

After unzipping and setting up JAVA_HOME and Windows Path:

c:\>java -version
openjdk version "17.0.5" 2022-10-18 LTS
OpenJDK Runtime Environment Corretto-17.0.5.8.1 (build 17.0.5+8-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.5.8.1 (build 17.0.5+8-LTS, mixed mode, sharing)

2. Spring Initializr + IntelliJ

I bought a JetBrains All Products Pack earlier this week (previously had been using IntelliJ CE + VS Code for Java + Angular personal development).

IntelliJ Ultimate Edition has great support for Spring Initializr.



























Here I am creating a new Spring Boot JAR project, specifying the Amazon Corretto JDK 17 that I just installed.































And selecting Spring Boot Starters (Spring Web, Spring Boot Actuator).

3. Since my goal this weekend is to study and learn about various aspects of AWS, I just need a quick and dirty Spring Boot App that exposes a REST endpoint.

I went to https://spring.io/guides/gs/actuator-service/ and copied over the HelloWorldController and Greeting model, ran it locally through IntelliJ and verified I could hit the REST endpoint on port 8080.

4. Confirmed I could run through IDE and hit the REST endpoint.

Also built the Spring Boot JAR and confirmed I could run that and hit the REST endpoint:

PS C:\work\spring-boot-aws\demo> ./mvnw package  
PS C:\work\spring-boot-aws\demo> java -jar .\target\demo-0.0.1-SNAPSHOT.jar