I would like to post my application made in spring boot using docker for the first time. However, a problem arose while posting it.
So, the image I uploaded to the conter does not display.
Here are the steps I took, and I'll add right away that I used gradle.
- I downloaded the Docker plugin to IntelliJ
- I created a Dockerfile in which I put:
In the terminal, I typed the following commands to build the project:
Then I typed (to create an image and display it):
And here is where the problem arises, I entered the following commands:
(I want to run on port
8081
because my app listens on port8080
. I don't know if it matters but that's how I did it)
I display the list using command: docker container ps
After typing the docker container ps command, no created container is displayed to me, I get an empty list, and after typing the first command I get logs (a string of characters and numbers, which probably indicates the success of the operation) but I do not know why the container is not created.
I have no idea what I'm doing wrong that it's not working, where I'm making a mistake. Is there something else I should do? In general, the spring boot application at this time should be running? What does it look like, I read some tutorials but unfortunately nothing helped, and I was doing the same way as them
CodePudding user response:
You can also create a Docker image with Maven plugin by defining in pom.xml and run 'mvn install':
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>
${project.groupId}/twitter.to.kafka.service:${project.version}
</name>
</image>
</configuration>
<executions>
<execution>
<!-- Create Docker image during mvn install -->
<phase>install</phase>
<goals>
<!-- Spring Boot use the Layered approach : to prevent creating a single fat jar, and use caching during image update -->
<goal>
build-image
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Can you try this instead of manually creating a Dockerfile ?
CodePudding user response:
try to run:
docker run -p 8081:8081 springreadyapp
i add a link to my repo which explain about that, in maven docker with spring