Estoy tratando de compilar mongo dentro de la ventana acoplable y quiero insertar la base de datos, la colección y el documento dentro de la colección que probé con la compilación de la ventana acoplable y debajo de mi Dockerfile
FROM mongo RUN mongosh mongodb://127.0.0.1:27017/demeter --eval 'db.createCollection("Users")' RUN mongosh mongodb://127.0.0.1:27017/demeter --eval 'var document = {"_id": "61912ebb4b6d7dcc7e689914","name": "Test Account","email":"test@test.net", "role": "admin", "company_domain": "test.net","type": "regular","status": "active","createdBy": "61901a01097cb16e554f5a19","twoFactorAuth": false, "password": "$2a$10$MPDjDZIboLlD8xpc/RfOouAAAmBLwEEp2ESykk/2rLcqcDJJEbEVS"}; db.Users.insert(document);' EXPOSE 27017y usando Docker Compose
version: '3.9' services: web: build: context: ./server dockerfile: Dockerfile ports: - "8080:8080" demeter_db: image: "mongo" volumes: - ./mongodata:/data/db ports: - "27017:27017" command: mongosh mongodb://127.0.0.1:27017/demeter --eval 'db.createCollection("Users")' demeter_redis: image: "redis"Quiero agregar los registros a continuación porque el servidor web los está usando en el backend. si hay una mejor manera de hacerlo estaría agradecido.
Lo que me sale es el siguiente error
demeter_db_1 | Current Mongosh Log ID: 61dc697509ee790cc89fc7aa demeter_db_1 | Connecting to: mongodb://127.0.0.1:27017/demeter?directConnection=true&serverSelectionTimeoutMS=2000 demeter_db_1 | MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017Saber cuándo me conecto al shell interactivo dentro del contenedor mongo y los agrego manualmente funciona bien.
root@8b20d117586d:/# mongosh 127.0.0.1:27017/demeter --eval 'db.createCollection("Users")' Current Mongosh Log ID: 61dc64ee8a2945352c13c177 Connecting to: mongodb://127.0.0.1:27017/demeter?directConnection=true&serverSelectionTimeoutMS=2000 Using MongoDB: 5.0.5 Using Mongosh: 1.1.7 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy). You can opt-out by running the disableTelemetry() command. ------ The server generated these startup warnings when booting: 2022-01-10T16:52:14.717+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem 2022-01-10T16:52:15.514+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted ------ { ok: 1 } root@8b20d117586d:/# exit exitSalud