AWS ECS, Run Java microservices using docker containers in ECS

In this entry I’m going to show an example to run Java microservices in containers in AWS, I’m using a simple web application with a provided source code from my last training that you can donwload from my github repository.

Please notice that refactoring any monolithic application it could be a very complex task and depends of each context as well as the analisys before to modernize any component to be decoupled, as reference this is is the initial architecture and how must to be after the modernization in containers.

AS-IS, a highly available environment for a monolithic Java application.

TO-BE, the highly available environment for the containeraized Java application

As same as my previuos entries, all information were taken from my last training, therefore some components were already provided:

  • Development IDE
  • Development Pipeline
  • A ECS Cluster
  • A RDS instance
  • A Custom VPC

Let’s get started.

Seguir leyendo

Docker, image layering/caching in action

This is a quick entry to show how the image layers works, according to docker documentation the «The order of Dockerfile instructions matter» and it is because each line in the configuration file is converted into an image layer (cached layer).

Docker image layers, taken from https://docs.docker.com/build/guide/layers/

This feature allows that every layer can be reused when the image is built or executed, each layer is read-only. For example, create the next python app and the next Dockerfile:

Seguir leyendo

Podman, basic steps for a Java project

Podman is an open source utility that can be used to create and mantain containers, and provides an good alternative to Docker.

In this entry I’m going to show how to execute some basic commands using a Java project. All source code is published in my GitHub repository.

Virtual machine management commands

Let’s take a look to the commands with the help parameter, I think they are very descriptive:

$ podman machine --help 
Manage a virtual machine

Description:
  Manage a virtual machine. Virtual machines are used to run Podman.

Usage:
  podman.exe machine [command]

Available Commands:
  info        Display machine host info
  init        Initialize a virtual machine
  inspect     Inspect an existing machine
  list        List machines
  rm          Remove an existing machine
  set         Sets a virtual machine setting
  ssh         SSH into an existing machine
  start       Start an existing machine
  stop        Stop an existing machine
Seguir leyendo

Docker, using bind mounts in a Java project

The bind mounts in a short is way to set a mount point from the host to the container, it means the files are accesible from the file system where the container is launched, for example it could be useful to mount the source code for a web site into the container and do some code changes in the UI and view them inmediatly without build again the Docker image.

Cool right?

Well for Java projects is not so cool, because when the source code is changed it must be compiled and packaged again to be executed or deployed, but the bind mounts could be useful too when there are some external files like configuration properties, input and output files to read, etc. So, if you are working on development environment or in your local machine, perhaps you would have to consider use the bind mounts to get access easily to the files when you are coding or testing new features.

In this entry I’m going to show how to apply in a Maven Java project. All code can be downloaded from my GitHub repository.

Seguir leyendo

Docker basic steps for a Java Project

In this entry I’m going to show how to build a docker image and deploy a Maven Java project from a simple jar file and execute it as micro service.

All code is published into my GitHub repository.

Build an image and run into a container

First, crate a file named Dockerfile at the top of your maven project folder with the next content:

# OS image
FROM alpine:3.14

# Exposed port
EXPOSE 8000

RUN apk --update-cache add openjdk11
WORKDIR /demo
COPY . .
CMD ["java","-jar", "target/demo-1.0-SNAPSHOT.jar", "start"]

This is a very simple configuration file, as you can see the selected image is an alpine linux exposed by the port 8000 and the openjdk11 is installed with the package manager, also I’ve setted a working directory name and all the content is copied from the Maven folder to the image. Finally, the jar is executed with the CMD command.

Seguir leyendo