I have to write 3 simple microservices, using spring boot, and dockerize them. Since I have just started reading about dockers I have encountered several issues.
To build docker images I am using this maven plugin:
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.0</version>
<configuration>
<imageName>example</imageName>
<baseImage>java</baseImage>
<entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<imageTags>
<imageTag>latest</imageTag>
</imageTags>
</configuration>
</plugin>
Requirements
- Docker containers have to run without ROOT user privilages.
- Building maven script should build docker containers.
- Database also needs to be dockerized (all microservices use one database)
My issues
I have test service .jar and everything works just fine (it connects to dockerized postgres) but when I run docker image (built with sudo mvn docker:build) of test service .jar I can't connect to postgres.
I have found that localhost in data source might be the issue:
spring.datasource.url=jdbc:postgresql://localhost:5432/dockertest
But I don't know what should I put in place of localhost.
I would appreciate any tips on how to easily create and run those docker images (meeting above requirements)