Docker × Java Building a development environment that is too simple

Java development environment construction with Docker

Overview

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)

environment

--macOS Catalina version 10.15.5

Constitution

The final configuration is as follows.

├── docker
│   └── java
│       └── Dockerfile
├── docker-compose.yml
└── server
    └── src
        ├── Main.class
        └── Main.java

procedure

1. Create docker-compose.yml

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

2. Create Dockerfile

Dockerfile



FROM openjdk:11-slim

RUN apt-get update
WORKDIR /usr/src

3. Create a test file

Create a test file called Main.java.

Main.java


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

4. Start Docker


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

5. Compile and run

//inspection
% docker-compose exec java bash

//compile
[email protected]:/usr/src# javac Main.java

//Run
[email protected]:/usr/src# java Main
Hello World!

reference

-I tried to prepare the java development environment with docker

Recommended Posts

Docker × Java Building a development environment that is too simple
Build a simple Docker + Django development environment
Build a simple Docker Compose + Django development environment
Build a development environment for Docker, java, vscode
Create a docker image that runs a simple Java app
Try to build a Java development environment using Docker
Creating a lightweight Java environment that runs on Docker
Procedure for building a Rails application development environment with Docker [Rails, MySQL, Docker]
Building a Lambda development environment in Eclipse
Build a PureScript development environment with Docker
Building a Kotlin development environment using SDKMAN
Let's create a Java development environment (updating)
What is Java and Development Environment (MAC)
[Ruby] Building a Ruby development environment on Ubuntu
Build a Java development environment on Mac
Spring Boot + Docker Java development environment construction
Build a Wordpress development environment with Docker
[Personal memo] Java development environment is ready
Java development environment
Creating a java web application development environment with docker for mac part1
Create a java web application development environment with docker for mac part2
Build a development environment for Docker + Rails6 + Postgresql
Build a WordPress development environment quickly with Docker
Build a web application development environment that uses Java, MySQL, and Redis with Docker CE for Windows
Prepare a scraping environment with Docker and Java
Points stuck in building VSCode & Java development environment
Create a Spring Boot development environment with docker
Build a Java development environment with VS Code
Java development environment memo
java development environment construction
Create a Java development environment using jenv on Mac
[Note] Create a java environment from scratch with docker
A command that definitely cleans the local docker environment
Create a Java, JavaScript team development environment (problem raising)
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
Learn the meaning of "passing the PATH" by building a Java development environment on Mac
[For beginners] Until building a Web application development environment using Java on Mac OS
I tried to create a java8 development environment with Chocolatey
WSL2 + VSCode + Docker development environment
I made a development environment with rails6 + docker + postgreSQL + Materialize.
What is a Java collection?
Java development environment (Mac, Eclipse)
[Java] Draw a simple pattern
Create a Java and JavaScript team development environment (gradle environment construction)
I tried to create a padrino development environment with Docker
[Eclipse] Flow of introduction as a Java development environment (I investigated various things at that time)
How to install Pry after building Rails development environment with Docker
Notes on building Kotlin development environment and migrating from Java to Kotlin
Build a browser test environment using Capybara in the Docker development environment
[Java] List method that determines whether a specific object is included
Building a haskell environment with Docker + VS Code on Windows 10 Home
Build a development environment for Django + MySQL + nginx with Docker Compose
Create a Vue3 environment with Docker!
[Eclipse Java] Development environment setting memo
Build a Node.js environment with Docker
3 Implement a simple interpreter in Java
Prepare Java development environment with Atom
Play Framework 2.6 (Java) development environment creation
How slow is a Java Scanner?
About the current development environment (Java 8)
Build Java development environment (for Mac)