1

I have two containers one running python and other one running mongodb. Now I want to run mongoimport command from my application container.

So how do I do it?

Alireza
  • 100,211
  • 27
  • 269
  • 172
  • You can use ```docker exec -it name_container or id_container bash or sh``` so when you are inside of container of mongodb use ```mongo import``` – julian salas Jul 08 '17 at 00:17

1 Answers1

0

docker exec should be reserved for debugging purposes.

Ideally, you would run mongoimport at build time from your Dockerfile, in order to make an image dedicated to seed your mongo database.
For instance, look at "How do I seed a mongo database using docker-compose?"

That way, you avoid any manual runtime operation.

If you must have a regular runtime operation, then you need to add to your image a cron, as I described here.
That way, you can execute that mongoimport on a regular basis, during the time the container is running.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The application is such that when new files get added it should be imported in database. Files would only be added at an interval yet I would like to automate that process. – Samip Kothari Jul 08 '17 at 13:52
  • @SamipKothari OK. I have edited the answer accordingly. – VonC Jul 08 '17 at 19:15