我有一个由React,Flask和MongoDB组成的应用程序作为数据库。
我的docker-compose.yml
看起来像
version: '3.7'
services:
frontend:
container_name: frontend
build:
context: frontend
dockerfile: Dockerfile
ports:
- "3000:80"
backend:
build: ./backend
ports:
- "5000:5000"
links:
- db
db:
image: mongo:latest
ports:
- "27017:27017"
烧瓶app.py
的初始部分看起来像
from flask import Flask, render_template, request, jsonify
from flask_cors import CORS
from bson.objectid import ObjectId
import pymongo
import json
import ssh
import OpenSSL
import pprint
import os
application = Flask(__name__)
cors = CORS(application)
cors = CORS(application)
client = pymongo.MongoClient('mongodb://mongodb:27017/')
db = client["my_db"]
但是,当我docker-compse build
和docker-compose up
时,我得到了
backend_1 | pymongo.errors.ServerSelectionTimeoutError: mongodb:27017: [Errno -2] Name or service not known
当我向后端请求时。
请帮忙吗?