Docker × Spring Boot environment construction

Docker × Spring Boot environment construction

Overview

Build a Spring Boot environment using Docker. To check the operation, display Hello World on the browser.

environment

--macOS Catalina version 10.15.5

Constitution

The final configuration will be as follows.

├── docker-compose.yml
└── server
    ├── HELP.md
    ├── build
    │   ├── classes
    │   │   └── java
    │   │       ├── main
    │   │       │   └── com
    │   │       │       └── example
    │   │       │           └── api
    │   │       │               └── ApiApplication.class
    │   │       └── test
    │   │           └── com
    │   │               └── example
    │   │                   └── api
    │   │                       └── ApiApplicationTests.class
    │   ├── generated
    │   │   └── sources
    │   │       ├── annotationProcessor
    │   │       │   └── java
    │   │       │       ├── main
    │   │       │       └── test
    │   │       └── headers
    │   │           └── java
    │   │               ├── main
    │   │               └── test
    │   ├── libs
    │   │   └── api-0.0.1-SNAPSHOT.jar
    │   ├── reports
    │   │   └── tests
    │   │       └── test
    │   │           ├── classes
    │   │           │   └── com.example.api.ApiApplicationTests.html
    │   │           ├── css
    │   │           │   ├── base-style.css
    │   │           │   └── style.css
    │   │           ├── index.html
    │   │           ├── js
    │   │           │   └── report.js
    │   │           └── packages
    │   │               └── com.example.api.html
    │   ├── resources
    │   │   └── main
    │   │       ├── application.properties
    │   │       ├── static
    │   │       └── templates
    │   ├── test-results
    │   │   └── test
    │   │       ├── TEST-com.example.api.ApiApplicationTests.xml
    │   │       └── binary
    │   │           ├── output.bin
    │   │           ├── output.bin.idx
    │   │           └── results.bin
    │   └── tmp
    │       ├── bootJar
    │       │   └── MANIFEST.MF
    │       ├── compileJava
    │       └── compileTestJava
    ├── build.gradle
    ├── gradle
    │   └── wrapper
    │       ├── gradle-wrapper.jar
    │       └── gradle-wrapper.properties
    ├── gradlew
    ├── gradlew.bat
    ├── settings.gradle
    └── src
        ├── main
        │   ├── java
        │   │   └── com
        │   │       └── example
        │   │           └── api
        │   │               └── ApiApplication.java
        │   └── resources
        │       ├── application.properties
        │       ├── static
        │       └── templates
        └── test
            └── java
                └── com
                    └── example
                        └── api
                            └── ApiApplicationTests.java

procedure

1. Create docker-compose.yml

This time it is a simple configuration with only one java container.

docker-compose.yml


version: '3.6'
services:
  java:
    image: openjdk:14-slim
    ports:
      - 8080:8080
    tty: true
    volumes:
      - ./server:/srv:cached
    working_dir: /srv

2. Create Gradle project

2.1 Create a Gradle project template with spring initializr スクリーンショット 2020-07-10 11.37.29.png

2.2 Download Gradle project template スクリーンショット 2020-07-10 11.43.22.png

2.3 Expand to project Create a server directory directly under the project directory. Extract ʻapi.zipdownloaded in 2.2 and move the contents directly underserver`.

3. Edit the application file

Edit server / src / main / java / com / example / api / ApiApplication.java as follows.

server/src/main/java/com/example/api/ApiApplication.java


package com.example.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class ApiApplication {

    @RequestMapping("/")
    public String home() {
        return "Hello World";
    }

    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }

}

4. Start Docker

//docker environment build
% docker-compose build

//Start docker in the background
% docker-compose up -d

5. Build Gradle

//Inspection in java container
% docker-compose exec java bash

//gradle build
[email protected]:/srv# sh gradlew build
...
BUILD SUCCESSFUL in 1m 38s
5 actionable tasks: 3 executed, 2 up-to-date

Make sure that the build directory is created directly under the server.

6. Run the application

[email protected]:/srv# java -jar build/libs/api-0.0.1-SNAPSHOT.jar

7. Operation check

Let's access http: // localhost: 8080 /. If Hello World is displayed, it is successful.

reference

-Docker + Spring-boot start -Spring Boot starting with Docker

Recommended Posts

Docker × Spring Boot environment construction
[Spring Boot] Environment construction (macOS)
Spring Boot environment construction with Docker (January 2021 version)
[Spring] Environment construction
Docker environment construction
◆ Spring Boot + gradle environment construction memo
Database environment construction with Docker in Spring boot (IntellJ)
Rails Docker environment construction
Spring Boot environment construction memo on mac
Spring boot development-development environment-
Try Spring Boot 1 (Environment construction ~ Tomcat startup)
Create a Spring Boot development environment with docker
MySQL 5.7 (Docker) environment construction memo
Redmine (Docker) environment construction memo
[Docker] Rails 5.2 environment construction with docker
[Docker] postgres, pgadmin4 environment construction
React environment construction with Docker
spring × docker
Node.js environment construction with Docker Compose
Environment construction with Docker for beginners
Laravel + Docker Laradock usage environment construction
Rails on Docker environment construction procedure
[Environment construction with Docker] Rails 6 & MySQL 8
Spring Boot gradle build with Docker
Create Spring Boot development environment on Vagrant
SQL statement learning ~ Environment construction ~ Docker + MySQL
GPU environment construction with Docker [October 2020 version]
Rails environment construction with Docker (personal apocalypse)
Laravel development environment construction with Docker (Mac)
[Java] Environment construction
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Java environment construction
Create Spring Boot-gradle-mysql development environment with Docker
[Docker] Development environment construction Rails6 / Ruby2.7 / MySQL8
Laravel + MySQL + phpMyadmin environment construction with Docker
Spring Boot Memorandum
gae + spring boot
[Environment construction] Spring Tool Suite4 installation (Mac)
About designing Spring Boot and unit test environment
Docker + DynamoDB local + C ++ environment construction and practice
Environment construction command memo with Docker on AWS
Kaggle environment construction using official Docker and vscode
How to make Spring Boot Docker Image smaller
Rails6 [API mode] + MySQL5.7 environment construction with Docker
JAVA + STS (Spring Tool Suite) environment construction procedure
Build Spring Boot project by environment with Gradle
A reminder of Docker and development environment construction
IntelliJ + Docker (APP + DB) + SpringBoot (Maven) environment construction
React + Django + Nginx + MySQL environment construction with Docker
Create Spring Boot environment with Windows + VS Code
LINE Bot x Java (Spring Boot) construction procedure
Wordpress local environment construction & development procedure with Docker
Penronse environment construction [Windows]
[Environment construction] Eclipse installation
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
[Flutter] Ubuntu 20.04 environment construction
Spring boot memo writing (1)
First Spring Boot (DI)
SPRING BOOT learning record 02
Spring Boot exception handling