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 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.
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