Docker Start Container

In this guide, we will see how to start a Docker container that runs a Spring Boot application.

When it comes to starting containers that have been created but are not currently running, Docker offers the docker start command. This command helps you kickstart such containers into action.

Docker Start Container - Step-By-Step Guide

Let's begin with creating a simple Spring boot application and dockering this Spring boot application.

Dockering Spring boot application

Step 1: Create a basic Spring Boot application. If you don't have one ready, the Spring Initializr is a fantastic place to generate a project. 

Step 2: Build your Spring Boot application:

mvn clean package

Step 3: Create a Dockerfile in the root of your project:

FROM openjdk:11-jre-slim
COPY target/my-spring-boot-app-0.0.1-SNAPSHOT.jar /usr/app/
WORKDIR /usr/app
ENTRYPOINT ["java", "-jar", "my-spring-boot-app-0.0.1-SNAPSHOT.jar"]

Step 4: Build the Docker image:

docker build -t my-spring-boot-app:latest .

Starting the Container

With your Spring Boot Docker image ready, let's start the container that runs a Spring Boot application:
docker run -d -p 8080:8080 my-spring-boot-app:latest

Here's a breakdown: 

-d: Runs the container in detached mode, freeing up your terminal. 

-p 8080:8080: Maps the container's port 8080 to your machine's port 8080. 

my-spring-boot-app:latest: This is the name and tag of the image we created earlier.

Verifying the Running Container

To ensure your Spring Boot application is running smoothly, use the following command to list out running containers:

docker ps

Next, visit http://localhost:8080 in your browser. You should see your Spring Boot application's landing page or endpoints.

Conclusion

In this guide, we have learned step by step how to dockerize a simple spring boot application and start the container that runs the spring boot application.

Related Container Management Guides

Comments