I have a backend that runs on Spring and I had to create a Docker container.
To do this, I created a .jar
file using Maven by running this mvn package
then I did the docker run build
command to create my container.
Here is the first content of my DockerFile.
FROM openjdk:17-jdk-alpine
COPY target/dwh_webservices-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 443
ENTRYPOINT ["java", "-jar", "/app.jar"]
I want to point out that my Container is perfectly functional with this first method.
However, it's a pain to have to run the command every time. Moreover, I would like to make pipelines and automate the creation of the .JAR
with Maven. So I decided to integrate the creation of the .JAR
in the Dockerfile.
For that, I followed this question that explains the Multi-stage and I created this Dockerfile :
#
# Build stage
#
FROM maven:3.8.3-openjdk-17 as build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package
#
# Package stage
#
FROM openjdk:17-jdk-alpine
COPY --from=build /home/app/target/dwh_webservices-0.0.1-SNAPSHOT.jar /usr/local/lib/app.jar
EXPOSE 443
ENTRYPOINT ["java", "-jar", "/app.jar"]
And when I run it, I have this error that appears:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host BACKENDSERV, port 1433 has failed. Error: "BACKENDSERV Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.
Since it's the exact same source code plus the fact that the first .jar
is working, then it should also work. Why, when using the second method, does the application fail to access the host?
What causes this change?