alybel
alybel

Reputation: 520

How to add a docker container to an existing docker network

I have the following challenge with docker: I have a postgres service up and running which is managed by a docker-compose and works just fine.

Now, I want to build additional but isolated docker services that connect to this postgres database (an do an analytical task for instance) and can read and write data from there.

I understand that I could just grow my docker-compose file, however I want to keep this slim and tidy. So, my idea is to put each additional service in its own docker image and connect this to the postgres database. This allows me to use the additional docker services as I need them.

The challenge I have with this, is: how do I connect from docker container X to the postgres database that's running in the other docker network?

Thanks for any help!

Upvotes: 1

Views: 1120

Answers (1)

Timir
Timir

Reputation: 1425

Placing containers in the same network is trivial:

docker run --name my_new_container --network my_docker_network_name my_image_name

Figuring out the right network name:

Now, docker compose creates a network based on the app folder it was run in. Run docker network ls to list all networks.

Hope this helps.

Upvotes: 3

Related Questions