The main purpose of Docker Compose is to spin up a set of Docker containers, which will then function as independent entities. By default, all containers will have a virtual network connection to all others, though you can change that if you wish; you will get that feature, since you have not specified a custom configuration.
Each of the containers will get a virtual IP address inside the virtual network set up by Docker. Since these are dynamic, Docker Compose makes it easier for you by creating internal DNS entries corresponding to each service. So, you will have two containers, which can be addressed as app
and db
respectively, either from themselves or the other. If you have ping installed, you can ping these names too, either via docker-compose exec
, or via a manually-created shell.
Thus, as we discovered in the comments, you can connect from app
to jdbc:postgresql://db:5432/media
, and it should work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…