Atulya
Atulya

Reputation: 93

Springboot + Postgres + Docker linking

I have one container of springboot application on docker,and one container of postgres with all the settings.How can I run both of them by linking them together. The image springboot-postgresql corresponds to spring boot application,and postgres refers to postgresql. Postgres is listening to 0.0.0.0,port 5432.

enter image description here

Please suggest,if there's another way other than making a .yml file and using docker compose up . Thanks for the help.

Upvotes: 0

Views: 53

Answers (1)

ZabdiAG
ZabdiAG

Reputation: 155

The way you can communicate between each container is using docker network,

First, you need to create a network:

$ docker network create sprintapp

Above, the command creates a network named sprintapp

Then, you need to specify to a container to be inside the network:

$ docker run --name [CONTAINERNAME] --network sprintapp [IMAGE]

This way, all containers within the network could talk to each other, using [CONTAINERNAME] as the URI to locate it.

More info about this:

docker run reference

docker network reference

Upvotes: 1

Related Questions