Docker + Spring-boot start


These days I'm touching Java or Spring. By the way, I decided to run it with Docker, so I will set it.


You can use Docker. The setting method is omitted.


Java (Spring boot) settings

Template download

Create a crisp template with Spring Initializr. I specified the following. I think anything is fine if it is not written.

item Contents
Project Gradle project
Language Java
Spring boot 2.2.0(SNAPSHOT)
packaging jar
Java version 11
Dependencies Lombok,Web

A little app refurbishment

It works as it is, but it only works, so I'll make some minor modifications. The content simply allows you to return a response. First, create ʻ` in the same row as the automatically generated class. The contents of the created file are as follows.

$ touch src/main/java/...(package)/
package hoge;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

public class IndexController {

    public String getIndexPage() {
        return "Hello World!";

Docker settings

I will write Dockerfile in various ways. It feels like I looked it up. Everyone built it locally and then ran it with Docker. I want to do everything with Docker, so copy the necessary files and build & execute. I think it's better not to hit COPY repeatedly like this, but I don't know how to deal with it, so I'll do it once.


FROM openjdk:latest

RUN mkdir /app
COPY ./gradlew /app
COPY ./build.gradle /app
COPY ./settings.gradle /app
COPY ./src /app/src
COPY ./gradle /app/gradle
ENTRYPOINT ["sh", "./gradlew", "bootRun"]


I'm ready, so I'll try it. It's OK if you hit from the local and get a proper response.

$ docker build -t spring-docker ./
#Spring will start on port8080, so set it to 3000 locally
$ docker run -p 3000:8080 spring-docker

If it starts without any problem, check it with curl. It is OK if it becomes as follows.

$ curl localhost:3000/index
  Hello World!


This time I set Docker + Spring boot. It was easier than I expected, and I want to touch Java for the first time in a while, so I want to make something a little more. As I wrote above, I wonder if it will be built on Docker unexpectedly. .. .. That's all for today.

Recommended Posts

Docker + Spring-boot start
docker review image creation-container start
Docker test DB does not start
mysql doesn't start up with docker.
[Linux] Start Apache container with Docker
How to start Camunda with Docker
docker memo
kubernetes + docker
spring × docker
About Docker
Docker Intellij
Docker basics
MySQL container does not start in Docker
Docker installation
About Docker
Docker command
[Docker] Start the container as soon as possible
Docker memorandum
[Docker] Start container, start bash in container, delete image
Understand Docker
Docker memorandum
Note: [Docker] How to start and stop
Eclipse --Springboot
multi-project docker build using jib
Eclipse --Springboot
Make SpringBoot1.5 + Gradle4.4 + Java8 + Docker environment compatible with Java11
Start SQL Server with Docker & register initial data
IntelliJ + Docker (APP + DB) + SpringBoot (Maven) environment construction