0

I have two separate projects which have their own docker-compose.yml files. They both want to start a database.

Is it possible that if the DB instance already exists and is running, the second Docker Compose can just use that running instance instead of trying to create its own?

The database is a simple example. Let's say the DB is setup to run on port 5555:5555. When I first run docker compose up and the DB starts, it's running on port 5555. Great! Now later on I run docker compose up for the second project (yes, I'll need to have both running at the same time) and it's setup to run the exact same DB on the exact same port, but that will fail/crash with a 'port in use' error.

I know I can just have each file have their own instance run on their own port. I get that. But it's annoying because then I'll need to have different connection strings for tooling, like DB Administration UI tools.

So I just want ONE instance of the DB to be running on my localhost to "keep things simple". Is this possible?

6
  • If Docker Compose will be guaranteed to be running the database by the time you start the second instance, then you can have a custom docker-compose.yml file for the additional instance that specifies the network for the first instance. Here you don't need to spin up a database service, just spin up the new instances you need. Commented Feb 27 at 22:11
  • Hi @halfer - so the trick is to have a custom network which both docker-compose.yml files use? and when a someone runs the second docker-compose.yml because it's the same custom network, it will check to see if the instances asked for (in the 2nd file) are running and if so ... skip/ignore? Commented Feb 28 at 4:38
  • That is my question to you. When you run the second project, will the first one always be running? If so, you don't need to make a check, you can just rely on the assumption that it will be there. Commented Feb 28 at 9:04
  • 1
    However, when you run the second project, if the first one might be running, then I'd run a Bash script to test whether the port is open, or whether the service can be found in docker ps etc. Then I'd start up just the new service, or all services, depending on the answer. Commented Feb 28 at 9:06
  • Kewl - appreciate the answers. My summary: docker haven't applied an OOTB solution for this. Commented Mar 1 at 5:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.