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?

  • Docker - Running Postgres Scripts inside Container
  • Docker container and docker container on VM
  • Docker Compose how to extend service with build to use an image instead
  • Godep not working in docker container
  • Docker remote api don't restart after my computer restart
  • Clone private git repo with dockerfile
  • How to set Java heap size (Xms/Xmx) inside Docker container?
  • (mac) dockers , commit changes in mongo doesn't work
  • CircleCI: MySQL starts on its own even after stopping the process
  • How to find the CMD command of a docker image?
  • Docker 1.6 and Registy 2.0
  • docker-machine in docker on server
  • 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.