If you want to make a Java application a Docker image, it is convenient to use jib.

Docker with many benefits

Docker is one of the containerization technologies, but there are many advantages to using it. I will not explain about Docker itself in this article because various merits can be found by searching on the net. However, I would like to personally emphasize that if you are deploying Java modules or archives directly in the production environment, there are many benefits to changing to the work of pushing the Docker image to the repository. I think you can get.

Docker hassle

Docker has many merits, but it also has some troublesome aspects. I have to write a Dockerfile. Learning commands and best practices for writing can be a hassle. It is also troublesome to build a Docker environment when the local development environment is Windows.

jib solved

If the application running on the Docker container is developed in Java, using jib provided by Google will cause some troubles related to Docker. Will be released from.

All you need to use jib (if you are using gradle) is build.gradle

plugins {
  id 'com.google.cloud.tools.jib' version '2.1.0'

It is just the setting.

And if you want to push with the image name docker-image-to-push / 1.0.0

jib.to.image = 'docker-image-to-push/1.0.0'

And just put it in build.gradle. Now run gradle jib to create a Docker image and push it. The amazing thing is that you only need this setup and you don't need a Docker environment locally. If you have an account on Docker Hub

jib.to {
  auth {
    username 'account'
    password 'pass'
  image 'account/repository:1.0.0'

You can try jib immediately by setting it to build.gradle like. (Change the account, pass, repository part according to the environment)

As you can see in the above example, the jib requires almost no settings, but it can be set in various ways. The first thing I want you to set is (when the encoding of the Java source file is UTF-8)

jib.container.environment = [JAVA_TOOL_OPTIONS: '-Dfile.encoding=UTF-8']

It is a setting. Without this, an error will occur if there is Japanese in the source file. You can check the settings that can be made from configuration.

This is the introduction of jib.

Recommended Posts

If you want to make a Java application a Docker image, it is convenient to use jib.
[Spring Boot] If you use Spring Boot, it was convenient to use a lot of util.
JAWJAW is convenient if you use WordNet from Java
Delegate is convenient to use when you want to reuse parts
[Java] I want to make it easier because it is troublesome to input System.out.println.
If you want to make a zip file with Ruby, it's rubyzip.
[Swift] If you want to use a URL that includes Japanese, use addingPercentEncoding.
If it is Ruby, it is efficient to make it a method and stock the processing.
How to make @Transactional work that does not work if you use it incorrectly
Find a value that is convenient to have a method and make it a ValueObject
If you want to use Mockito with Kotlin, use mockito-kotlin
Program to determine if it is a leap year
[# 3 Java] Read this if you want to study Java! ~ Carefully selected ~
I want to make a list with kotlin and java!
I want to make a function with kotlin and java!
[Java] Make it a constant
If you want to mock a method in RSpec, you should use the allow method for mock and the singleton method.
What to do if you get a gcc error in Docker
ProxyFactory is convenient when you want to test AOP in Spring!
If you want to change the Java development environment from Eclipse
Make a C compiler to use with Rust x CLion with Docker
[Docker] Magic command when you want to wipe out none image
Use Jenkins to build inside Docker and then create a Docker image.
How to make a Java array
A story that may make you happy if you create a Sorry Page image to put kubernetes into production
If you want to use Oracle JDK 11 from September (add Amazon Corretto)
I want to summarize Apache Wicket 8 because it is a good idea
A shell script that builds a Docker image and pushes it to ECR
Memo: [Java] If a file is in the monitored directory, process it.
[JPA] Personal memo Paging processing is very convenient if you use Pageable
Java beginner tried to make a simple web application using Spring Boot
I tried to make a talk application in Java using AI "A3RT"
I want to develop a web application!
How to make a Java calendar Summary
How to make a Discord bot (Java)
[Java] Beginners want to make dating. 1st
Is it a loss if you don't know? Rails [Super] 5 selections to find error mistakes to escape from beginners
Let's create a TODO application in Java 2 I want to create a template with Spring Initializr and make a Hello world
Since the image of the lock screen of Windows 10 is beautiful, I wanted to make it a slide show of wallpaper
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do when you want to delete a migration file that is "NO FILE"
How to create a small docker image of openjdk 11 (ea) application (1GB → 85MB)
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
When is it said that you can use try with a Swift error?
It took a month from application to taking the Oracle Java SE 11 Silver
I want to play a GIF image on the Andorid app (Java, Kotlin)
[Java] Why do you bother to use the interface (Spring is also available)
I want you to use Scala as Better Java for the time being
[Small story] I tried to make the java ArrayList a little more convenient
[Introduction to Docker] Create a Docker image for machine learning and use Jupyter notebook
[Java] When putting a character string in the case of a switch statement, it is necessary to make it a constant expression
Even if I want to convert the contents of a data object to JSON in Java, there is a circular reference ...
[Swift] If the support of the application is iOS 11 or later, it was not necessary to use Int and Int64 properly
[Solution] What to do if you get a Docker error'ERROR: Cannot connect to the Docker daemon at unix: ///var/run/docker.sock. Is the docker daemon running?'
If you want to modify database columns etc.
Connect to Aurora (MySQL) from a Java application
I did Java to make (a == 1 && a == 2 && a == 3) always true
How to make Spring Boot Docker Image smaller
I want to use java8 forEach with index
A note when you want Tuple in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java