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.
Dockerfile
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"]
Main.java
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