Skip to content

Instantly share code, notes, and snippets.

@jschwarty
Created September 14, 2016 17:50
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jschwarty/6f9907e2871d1ece5bde53d259c18d5f to your computer and use it in GitHub Desktop.
Save jschwarty/6f9907e2871d1ece5bde53d259c18d5f to your computer and use it in GitHub Desktop.
Docker compose for mongodb and seed containers
version: '2'
services:
mongodb:
image: mongo:3.2.6
ports:
- "27017:27017"
mongo-seed:
image: mongo:3.2.6
links:
- mongodb
volumes:
- ./seed-data:/seed-data
command:
'bash -c "mongoimport --host mongodb --type json --file /seed-data/projects.json --jsonArray"'
@ravecat
Copy link

ravecat commented Mar 8, 2019

Thank you for gist. I tried your method. But code probably doesn't works because mongo_seed cannot reach db from mongo. As I understand links wait container run, but not prepared db.

I created branch for test here git clone https://github.com/ravecat/mendeleev.git --single-branch --branch issue/seed_mongo_docker_compose.

If I check docker container logs mongo_seed I get

Failed: error connecting to db server: no reachable servers
imported 0 documents

But I can run mongoimport command from host system and it will be successfully or run mongo with any custom port (in my example mongo --port 27019)

Could you clarify that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment