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": "jsmith@gmail.com",
    "age": 40,
    "admin": false
  },
  {
    "name": "Jen Ford",
    "email": "jford@gmail.com",
    "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 Answers1

2

Check this Answer

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

mongo_seeding: build: ./mongo_seed .

Change it to build:mongo_seed/.

Madev
  • 46
  • 4
  • I have found this https://stackoverflow.com/questions/54911021/unable-to-start-docker-mongo-image-on-windows. According this post It is not possible to run mongbodb container with data directory..... – MD. Ashfaqur Rahman Tahashin Nov 18 '19 at 06:56