Build a simple environment just by installing a Java container on Docker.
I will introduce up to the point where the program is mastered and the proof Hello World!
Is output to the console (laugh)
--macOS Catalina version 10.15.5
The final configuration is as follows.
├── docker
│ └── java
│ └── Dockerfile
├── docker-compose.yml
└── server
└── src
├── Main.class
└── Main.java
It has a simple configuration with only one java container.
docker-compose.yml
version: '3.6'
services:
java:
build: ./docker/java
ports:
- 8080:8080
tty: true
volumes:
- ./server/src:/usr/src:cached
Dockerfile
FROM openjdk:11-slim
RUN apt-get update
WORKDIR /usr/src
Create a test file called Main.java.
Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
//docker build
% docker-compose build
//Start docker in the background
% docker-compose up -d
//Verification
% docker-compose ps
Name Command State Ports
-------------------------------------------------------------
java-spring_java_1 jshell Up 0.0.0.0:8080->8080/tcp
//inspection
% docker-compose exec java bash
//compile
root@5b7be900c329:/usr/src# javac Main.java
//Run
root@5b7be900c329:/usr/src# java Main
Hello World!
-I tried to prepare the java development environment with docker
Recommended Posts