1024programmer Java How to connect to mongodb as docker image from another container application

How to connect to mongodb as docker image from another container application

First I pulled the mongoDb image

sudo docker pull mongo
 

And run the docker mongodb container:

sudo docker run --name database -d -p 27017:27017 mongo --noauth --bind_ip=0.0.0.0
 

I see that my Docker container works:

300b779a63a9 mongo "docker-entrypoint..." 30 minutes ago Up 30 minutes
 

Now I’m trying to connect to it via my docker app

sudo docker run -v ~/Desktop/Template/universal_skillskill -it --link 300b779a63a9:300b779a63a9 alexa
 

And…I received a message that the connection was refused:(

Uncaught exception: MongoError: failed to connect to server [0.0.0:27017] on first connect [MongoError: connect ECONNREFUSED 0.0.0.0:27017]
 MongoError: failed to connect to server [0.0.0:27017] on first connect [MongoError: connect ECONNREFUSED 0.0.0.0:27017]
 

I checked and my application works on the locally installed mongodb, but it cannot communicate with the docker mongoDb container: (What am I doing wrong? Can someone please help me 🙂

1>yamenk..:


You need to connect to, 300b779a63a9:27017 as this is the link name you specified for mongodb.


Like this in my container webapp mongoose.connect('mongodb://:300b779a63a9:27017');

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/772199

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索