首页 > 解决方案 > 码头工人 | 姜戈 | MongoDB 困境

问题描述

我不是专业的开发人员,但我喜欢用谷歌搜索东西,而且大多数时候,我都成功了。这一次,经过数周的尝试,我放弃了。我正在尝试构建和执行一个 docker 应用程序,但它只是拒绝这样做,并且它的开发人员不在我们身边。

码头工人-compose.yml

version: "3.9"
services:
  web_app:
    build:
      context: ./
      dockerfile: web_app/Dockerfile
    ports:
      - "8000:8000"
    volumes:
      - ./web_app:/app
    command: sh -c "python manage.py runserver 0.0.0.0:8000"
    environment: 
      - DEBUG=1
      - DATABASE=mongo
      - MONGO_CREDS=${MONGO_CREDS}
    volumes:
      - ./data:/data/
  queuing:
    build:
      context: ./
      dockerfile: Queuing/Dockerfile
    environment:
      - DATABASE=mongo
      - MONGO_CREDS=${MONGO_CREDS}
    restart: always
  checking:
    build:
      context: ./
      dockerfile: Checking/Dockerfile
    environment:
      - DATABASE=mongo
      - MONGO_CREDS=${MONGO_CREDS}
    restart: always
  fetching:
    build:
      context: ./
      dockerfile: Fetching/Dockerfile
    environment:
      - DATABASE=mongo
      - MONGO_CREDS=${MONGO_CREDS}
    restart: always
    volumes:
      - ./data:/data/
  exporting:
    build:
      context: ./
      dockerfile: Exporting/Dockerfile
    environment:
      - DATABASE=mongo
      - MONGO_CREDS=${MONGO_CREDS}
    restart: always
    
    volumes:
      - ./data:/data/

码头工人服务.yml

version: "3.9"
services:
  mongo:
    image: mongo
    restart: always
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: <ENTER PASSWORD HERE>
    volumes:
      - mongo-db:/data/db


  express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: admin
      ME_CONFIG_MONGODB_ADMINPASSWORD: <ENTER PASSWORD HERE>
    depends_on:
      - mongo

volumes:
  mongo-db:

我构建并启动了 docker,没有问题,没有错误。

docker-compose -f docker-services.yml  up -d --build
docker-compose up -d --build

还,

root@ubuntu:/home/vikas/Desktop/MTR/Test# docker ps
CONTAINER ID   IMAGE            COMMAND                  CREATED          STATUS          PORTS                                           NAMES
5c9c7c2e6dc7   test_checking    "python -u /app/app.…&quot;   37 minutes ago   Up 37 minutes                                                   test_checking_1
0a8ea2ee9c8c   test_web_app     "sh -c 'python manag…&quot;   37 minutes ago   Up 37 minutes   0.0.0.0:8000->8000/tcp, :::8000->8000/tcp       test_web_app_1
d97509b73813   test_fetching    "python -u /app/app.…&quot;   37 minutes ago   Up 37 minutes                                                   test_fetching_1
a1d3204b4243   test_exporting   "python -u /app/app.…&quot;   37 minutes ago   Up 37 minutes                                                   test_exporting_1
ff9bdb9943a2   test_queuing     "python -u /app/app.…&quot;   37 minutes ago   Up 37 minutes                                                   test_queuing_1
d5c27de9ec9d   mongo-express    "tini -- /docker-ent…&quot;   38 minutes ago   Up 37 minutes   0.0.0.0:8081->8081/tcp, :::8081->8081/tcp       test_express_1
89da15468de5   mongo            "docker-entrypoint.s…&quot;   38 minutes ago   Up 38 minutes   0.0.0.0:27017->27017/tcp, :::27017->27017/tcp   test_mongo_1

但是,有一个我无法解决的错误,

#docker logs d5c27de9ec9d -f
    Welcome to mongo-express
    ------------------------
(node:9) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
    **Could not connect to database using connectionString: mongodb://mongo:27017"**
    (node:9) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [Error: connect ECONNREFUSED 172.18.0.2:27017
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
      name: 'MongoNetworkError'

我什至测试了连接性,

root@ubuntu:/home/vikas/Desktop/MTR/Backup# mongo -host 127.0.0.1:27017 admin -u admin -p admin
MongoDB shell version v3.6.8
connecting to: mongodb://127.0.0.1:27017/admin
Implicit session: session { "id" : UUID("05b23477-2dfa-447d-9bae-9f2a106c7046") }
MongoDB server version: 5.0.3
WARNING: shell and server versions do not match
Server has startup warnings: 
{"t":{"$date":"2021-10-19T09:57:06.221+00:00"},"s":"I",  "c":"STORAGE",  "id":22297,   "ctx":"initandlisten","msg":"Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem","tags":["startupWarnings"]}

> show dbs 
admin             0.000GB 
config            0.000GB 
local             0.000GB 
mtr-bulk-ld-tool  0.000GB

任何提示将不胜感激。

标签: mongodbdocker

解决方案


推荐阅读