How to export Mongo-database using Docker?

I use “mongoDB” image in docker-container.
When I run command for export DB to csv:

docker exec -i 418f46e5595d  mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone --out ./info.csv

File saved in folder where container is working. How can I save it on my machine?

  • tinyproxy not tracing xmlhttprequest
  • HHVM inside Docker always running as root
  • Unable to use docker due to ZScaler and certificate issues
  • centos 7.3 docker-engine conflicts with docker-common-2
  • How to use Makefile in docker-machine
  • Do I first need docker environment before starting my project?
  • How to run an application as 100 services with docker? [closed]
  • How to enable Spark mesos docker executor?
  • How to join the default bridge network with docker-compose?
  • AWS ECS container exiting without specific reason
  • How to share host network bridge when using docker in docker
  • How to inform Maven/JVM options for S2I build in OpenShift3
  • 2 Solutions collect form web for “How to export Mongo-database using Docker?”

    remove the --out option so it will export to stdout and redirect output to a file, something like this:

    docker exec -i 418f46e5595d  mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone | gzip > info.csv
    

    You might want to redirect error messages to a different stream, so:

    docker exec -i 418f46e5595d  mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone 2>/tmp/mongoexport.err | gzip > info.csv
    

    My decision:
    1) export
    docker exec -i 418f46e5595d mongoexport --db saveInfo --collection infoobjects --type=csv --fields _id,postLink,postTitle,contactPhone --out
    ./info.csv

    2)copy to my machine

    docker cp webspider_mongo_1:/data/info.csv .

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.