且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法从其他Docker容器连接到MongoDB容器

更新时间:2022-11-29 19:47:12

我有一个类似构建的应用程序,它在两个单独的容器中使用flask和mongodb.我注意到您的撰写和我的撰写之间的区别是,每个容器都有提到的卷,但是没有定义卷,就像这样:

I have a similarly built app using flask and mongodb in two separate containers. One difference that I notice between your compose and mine, is that you have volumes mentioned for each container, but no volume definition, like so:

version: "3"
services:
  web:
    image: jzakilla/bookfinderpy
    command: nginx -g "daemon off;"
    container_name: webapp
    ports:
      - 80:80
      - 443:443 # expose internal container ports to host
  db:
    image: mongo
    container_name: mongodb
    ports:
      - 27017:27017
    volumes:
      - book_db:/data/db
volumes:
  book_db:
    driver: local  

没有卷部分,没有驱动程序告诉容器如何访问数据,我想容器会旋转,但实际上无法启动mongo服务,从而给您带来拒绝的错误.

Without a volume section, and a driver to tell the container how to access the data I would imagine the container would spin up, but not actually be able to start the mongo service, thus giving you a denied error.