I have a SpringBoot application, that runs perfectly on Tomcat and connects to a Postgres database.
e.g. application.properties
# approval
Solution for Mac: Inside your docker container simply have the db host set to host.docker.internal
. This will be forwarded to the host the docker container is running on. Reference
Solution for Linux: Actually what you really need to do is connect your container with Postgres running on host system, so for that we need to tell Docker to set network mode to host.
docker run -it --network=host -p 8081:8081 --name containerName 'imageName'
Or using docker-compose.yml
:
To start the containers just issue following command docker-compose up
version: '3.7'
services:
configurator:
container_name: 'nameOfContainer'
image: 'imageName'
network_mode: "host"
ports:
- "8081:8081"
restart: on-failure
For further learning please follow the docs.