-1

I have two containers: for main website and for forum. Both have their own databases. But I need to fetch some information within forum (Laravel) from website-database.

I tried everything in my .env: SECOND_DB_HOST=

  • 172.20.0.2 (website docker container ip adress)
  • localhost
  • 127.0.0.1
  • site-db (website docker container name)

SECOND_DB_PORT= should be 3306 in any case, I suppose?

Every time I get "connection refused". Within the website-container the first database works great.

Do I need to some sort of bridge or how is it possible?

enter image description here

Nokt
  • 29
  • 5
  • 1
    Use docker-compose - and you can connect by service name – Maksim Apr 30 '23 at 20:14
  • 1
    Do you have a [mcve] that shows the setup (not a screen shot of a management application but actual source code)? You normally would not directly try to access another service's database, but instead make an API call to the other service itself, but if the two services are set up separately you'll hit similar networking problems. – David Maze May 01 '23 at 12:36
  • 1
    If your screen shot is of Docker Desktop's representation of Compose projects, are you trying to set up [Communication between multiple docker-compose projects](https://stackoverflow.com/questions/38088279/communication-between-multiple-docker-compose-projects)? – David Maze May 01 '23 at 12:38

1 Answers1

1

So I successfully tried bridges and it works!

docker network create my-network

and then all 4 containers into new network..

docker network connect my-network CONTAINER_ID

and then the first DB is accessible by it's name! :-)

Nokt
  • 29
  • 5