Basically, all compose_* containers, are attached to a different Docker Network:, as well as test1, is associated to another network.
$ docker network inspect development_default | grep 'Name\|IPv4' "Name": "development_default", "Name": "compose_postgres", "IPv4Address": "172.20.0.2/16", "Name": "compose_elastic", "IPv4Address": "172.20.0.4/16", "Name": "compose_mongo", "IPv4Address": "172.20.0.3/16", These containers were created through Docker Compose, without specifying a custom network. If no custom network is defined on your Docker Compose file, docker will create a custom network which uses the name of the directory from were you have your build environment. That's why the development, name of the directory which was holding the files for generating these containers, was used when creating a network for them.
When executed the command $ docker run --name test1 repo/myapp:stage_1605191501, it was not used the option --network in order to specify the Docker Network development_default, and besides that, test1 would not be able to reach compose_postgres: compose_postgres has 5432 port exposed to the host network and it is also visible for development_default network (172.20.0.0/16), and the Django app which is called on the ENTRYPOINT of test1, is pointing to 0.0.0.0, and not for the IP of compose_postgresthem.
When executed the command
$ docker run --name test1 repo/myapp:stage_1605191501, no--networkwas specified, sotest1will be associated to the defaultbridgenetwork.compose_postgreshas 5432 port exposed to the host network and it is associated todevelopment_defaultnetwork (172.20.0.0/16).
Answer (steps):
- provide static IP for
compose_postgres - define this IP for the Django app definitions, inside the image of
test1, in order to make its connectionprovide connection from the app tocompose_postgresdatabase - incorporate thedefine
test1development_defaulttoas thedevelopment_default--networkfor (custom network used bytest1when runningcompose_postgresdocker run)
For further reference: