Cloud Native 11 min read

Using Docker with IntelliJ IDEA for Spring Boot Development and Redis Integration

This article explains how to set up Docker on Windows, integrate it with IntelliJ IDEA, build and run a Spring Boot application inside a container, and connect the containerized service to a Redis instance, including configuration, Maven plugin setup, and troubleshooting steps.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Using Docker with IntelliJ IDEA for Spring Boot Development and Redis Integration

During front‑end integration, the author found that restarting the service after code changes caused errors for the front‑end, so they adopted Docker to provide a stable development environment while continuing work.

1. Introduction to Docker

Docker has three basic concepts: Dockerfile – a template describing the steps to build an image; image – a file used to create containers; container – a runnable instance of an image that behaves like an isolated OS.

Analogy: a Dockerfile is like a concrete mix recipe, the image is the mixed concrete, and each container is a separate room built from that concrete.

For developers Docker enables writing code locally, pushing the program to a test environment, fixing bugs in the development environment, and finally merging code to the release branch.

2. Docker on Windows integrated with IDEA

2.1 Install Docker on Windows – ensure the Windows Subsystem for Linux (WSL) is enabled before installation.

2.2 Docker configuration – open port 2375 and add the line host: [ \"0.0.0.0:2375\"]. Example daemon.json content:

{<br/>  "debug": false,<br/>  "experimental": false,<br/>  "features": { "buildkit": true },<br/>  "hosts": ["tcp://0.0.0.0:2375"],<br/>  "insecure-registries": [],<br/>  "registry-mirrors": ["https://hub-mirror.c.163.com","https://mirror.baidubce.com"]<br/>}

2.3 Connect IDEA to Docker – older IDEA versions need the Docker plugin; newer versions can connect directly. Successful connection shows “Connection successful”. For local applications use tcp://localhost:2375, for LAN use the IPv4 address, and for remote machines use the public IP.

If the IP connection fails, run the following command in an elevated Windows terminal to proxy port 2375:

netsh interface portproxy add v4tov4 listenport=2375 connectaddress=127.0.0.1 connectport=2375 listenaddress=<your ipv4> protocol=tcp

Also add a firewall rule:

netsh advfirewall firewall add rule name=\"docker_daemon\" dir=in action=allow protocol=TCP localport=2375

After configuring the host, the author experienced intermittent connectivity issues that were resolved by resetting the port proxy.

3. Build and run a Spring Boot application in Docker

Sample controller:

@RestController<br/>public class TestController {<br/>    @GetMapping("/get/hello")<br/>    public String get() { return "Hello World"; }<br/>}<br/><br/>@SpringBootApplication<br/>public class SpringBootWithDockerStarter {<br/>    public static void main(String[] args) { SpringApplication.run(SpringBootWithDockerStarter.class, args); }<br/>}

Add a Dockerfile to the project:

# Base image<br/>FROM java:8<br/>VOLUME /tmp<br/># Copy jar and rename<br/>ADD ./target/SpringBootWithDocker-1.0-SNAPSHOT.jar DemoApp.jar<br/># Start the application<br/>ENTRYPOINT ["sh","-c","java -jar DemoApp.jar"]

Project structure should place the Dockerfile where the ADD command can locate the jar.

Configure the Maven Docker plugin (spotify docker‑maven‑plugin) in pom.xml:

<build><br/>  <plugins><br/>    <plugin><br/>      <groupId>org.springframework.boot</groupId><br/>      <artifactId>spring-boot-maven-plugin</artifactId><br/>    </plugin><br/>    <plugin><br/>      <!-- Docker image plugin --><br/>      <groupId>com.spotify</groupId><br/>      <artifactId>docker-maven-plugin</artifactId><br/>      <version>1.2.2</version><br/>      <executions><br/>        <execution><br/>          <id>build-image</id><br/>          <phase>package</phase><br/>          <goals><br/>            <goal>build</goal><br/>          </goals><br/>        </execution><br/>      </executions><br/>      <configuration><br/>        <imageName>${project.artifactId}</imageName><br/>        <imageTags><imageTag>latest</imageTag></imageTags><br/>        <dockerDirectory>${project.basedir}</dockerDirectory><br/>        <dockerHost>http://127.0.0.1:2375</dockerHost><br/>        <resources><br/>          <resource><br/>            <targetPath>/</targetPath><br/>            <directory>${project.build.directory}</directory><br/>            <include>${project.build.finalName}.jar</include><br/>          </resource><br/>        </resources><br/>      </configuration><br/>    </plugin><br/>  </plugins><br/></build>

After packaging, the generated JAR appears in the target directory, and the Docker image can be built and run. Access the endpoint localhost:8080/get/hello to verify the service.

Optional: fix Docker console Chinese garbled characters by adding JVM options: -Dfile.encoding=UTF-8<br/>-Dsun.jnu.encoding=UTF-8 4. Connect to Redis running inside Docker

Obtain the Redis password from the container, then connect with: docker exec -it containerName /bin/bash Inside the container run redis-cli and authenticate with auth {password}. Adjust the Spring Boot application.yml to point to the host IP and the mapped port (e.g., 49153) and include the password.

After rebuilding and redeploying, the application can read and write Redis data via the provided controller endpoints.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerredismavencontainerizationSpring BootIntelliJ IDEAWindows
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.