Home > Enterprise >  How to connect a Dev Container to another Container?
How to connect a Dev Container to another Container?

Time:08-18

for this question im working with prisma's dev container: https://github.com/prisma/prisma/tree/main/.devcontainer

once i open that repo inside of a container using the remote container plugin in visual studio and run some Jest Tests that rely on docker services defined in the https://github.com/prisma/prisma/tree/main/docker folder, i get the error of "cant connect to database" for all databases...

it's like if the dev container had no idea those services exist... on my pc, looking at docker desktop i see the services up and running but the devcontainer can't... why?

i find it weird that i had to change any type of setting since this files are from the prisma repo, they are suposed to be ready for action once downloaded... right?

CodePudding user response:

If the script is runing this line to get env in your devcontainer as below.

const connectionString = (
    process.env.TEST_MYSQL_URI_MIGRATE || 'mysql://root:root@localhost:3306/tests-migrate'
  ).replace('tests-migrate', 'tests-migrate-dev')
`

The localhost in the connection string means the localhost in your devcontainer but not your host machine.

You should access the localhost of your host machine instead.

The fix is set the TEST_MYSQL_URI_MIGRATE environment variable instead like

TEST_MYSQL_URI_MIGRATE=mysql://root:[email protected]:3306/tests-migrate

For the details how to access the localhost of host machine, please read this question

  • Related