jeudi 30 mars 2017

Docker How to connect to MongoDB from Web Service inside Container

Currently I want to setup a Linux Server with MongoDB and a WebServer which saves stuff inside this DB. I need them both to run inside Docker containers.

My problem is that my WebServer doesnt seem to "see" the MongoDB from inside its container.

What ive tried so far is: run MongoDB with

docker run -p 27017:27017 -v... repoimage

it initializes fine and I can access this DB through the mongoshell without any problems. Also the Webserver can access the DB if it DOESNT run in a container but just on the host as java application.

When I try now to run the server through a container I get a java exception saying "Connection refused" (which is thrown when he cant open the socket)

(Important: the server accesses the mongodb through "localhost")

I thought that container networks are "linked" together. Does anyone have the same problem?




Aucun commentaire:

Enregistrer un commentaire