1

My directory structure:

root
  - mongo_seed
    - Dockerfile
    - init.json
  - docker-compose.yml
  - Dockerfile

Docker compose file

version: "3"
services:
 web:
  container_name: "hgbackend"
  build: .
  image: tahashin/hgbackend:v2
  ports:
   - "3000:3000"
  links:
   - mongodb
  depends_on:
   - mongodb
 mongodb:
   image: mongo:latest
   container_name: "mongodb"
   ports:
    - "27017:27017"
 mongo_seeding:
    build: ./mongo_seed .
    volumes:
      - ./config/db-seed:/data
    links:
      - mongodb
    depends_on:
      - mongodb

docker file under mongo_seed directory

FROM mongo:latest

    COPY init.json /init.json
    CMD mongoimport --host mongodb --db alifhala --collection honcollection --type json --file /init.json --jsonArray

mongodb test data file init.json

[
  {
    "name": "Joe Smith",
    "email": "[email protected]",
    "age": 40,
    "admin": false
  },
  {
    "name": "Jen Ford",
    "email": "[email protected]",
    "age": 45,
    "admin": true
  }
]

After running docker-compose up in windows powershell database and collection is not creating and data is not dumping. After running mongo query in docker it is showing only 3 databases: local, admin, config

1 Answer 1

2

Check this Answer

https://stackoverflow.com/a/48179360/1124364

mongo_seeding: build: ./mongo_seed .

Change it to build:mongo_seed/.

Sign up to request clarification or add additional context in comments.

1 Comment

I have found this stackoverflow.com/questions/54911021/…. According this post It is not possible to run mongbodb container with data directory.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.