Node / Express app can't connect to docker mongodb

前端 未结 1 1675
悲哀的现实
悲哀的现实 2021-01-03 04:04

I want to run a node app that uses express and connects to a (boot2docker) docker mongo container.

When I first wrote the app, I was using a locally installed instan

1条回答
  •  悲哀的现实
    2021-01-03 04:05

    You need to publish the appropriate port on the container with the -p argument i.e:

    docker run -p 27017:27017 -v "$(pwd)":/data --name mongo -d mongo mongod --smallfiles
    

    The will make port 27017 accessible on the host (the VM in your case) and forward traffic to port 27017 on the container.

    0 讨论(0)
提交回复
热议问题