[DOCKER] How to create a Java environment in just 3 seconds


I will explain how to create a java environment in an instant using software called Docker. Bugs caused by managing several Java versions on the local machine. That's it.


Create a directory with any name. Then create a Dockerfile and Main.java in that directory. The contents are as follows.


FROM openjdk:7
#Save the file in the directory containing the Dockerfile to the container.
COPY . /usr/src/myapp
#Specify the working directory
WORKDIR /usr/src/myapp
#Compile in a container
RUN javac Main.java
#In a container"java Main"To run
CMD ["java", "Main"]


public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!!");

Next, create a Docker image. Execute the following command in the current directory.

docker build -t java_image .

Next, make the created image a container.

docker run -t java_image

Then Main is executed and the output is as follows.

Hello World!!

If you want to learn about Docker while moving your hands, the following book is recommended.

Yuichi Ito: Learn the basics in just one day! Docker / Kubernetes Super Primer

Recommended Posts

How to create a Java environment in just 3 seconds
How to create a data URI (base64) in Java
[Java] How to create a folder
How to create a new Gradle + Java + Jar project in Intellij 2016.03
How to display a web page in Java
Try to create a bulletin board in Java
How to create a theme in Liferay 7 / DXP
How to easily create a pull-down in Rails
How to create a method
How to create a Spring Boot project in IntelliJ
I tried to create a Clova skill in Java
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
How to make a Java container
How to learn JAVA in 7 days
Create a database in a production environment
How to use classes in Java?
How to name variables in Java
How to make a Java array
How to concatenate strings in java
I tried to create a java8 development environment with Chocolatey
How to create a lightweight container image for Java apps
How to create a placeholder part to use in the IN clause
I just wanted to make a Reactive Property in Java
How to store a string from ArrayList to String in Java (Personal)
What happened in "Java 8 to Java 11" and how to build an environment
Create a method to return the tax rate in Java
How to develop and register a Sota app in Java
How to simulate uploading a post-object form to OSS in Java
How to create a service builder portlet in Liferay 7 / DXP
How to make a Java calendar Summary
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
[Rails] How to execute "rails db: create" etc. in production environment EC2
How to reflect seeds.rb in production environment
How to insert a video in Rails
How to implement a job that uses Java API in JobScheduler
How to do base conversion in Java
[Introduction to Java] How to write a Java program
How to create a Maven repository for 2020
How to automatically operate a screen created in Java on Windows
Let's create a Java development environment (updating)
How to make a Discord bot (Java)
Create a TODO app in Java 7 Create Header
How to implement coding conventions in Java
How to embed Janus Graph in Java
How to print a Java Word document
How to get the date in java
[Swift5] How to create a splash screen
[rails] How to create a partial template
How to use environment variables in RubyOnRails
How to publish a library in jCenter
How to test a private method in Java and partially mock that method
How to create a query using variables in GraphQL [Using Ruby on Rails]
[Personal memo] How to interact with a random number generator in Java
How to develop from VScode in a remote destination environment or a remote destination container environment
To create a Zip file while grouping database search results in Java
Try to create a browser automatic operation environment using Selenide in 5 minutes
[Docker] How to create a virtual environment for Rails and Nuxt.js apps
How to pass a proxy when throwing REST over SSL in Java