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?

  • AWS Elastic Beanstalk, Dockerrun.aws.json and multiple ports on docker run [duplicate]
  • Dockerhub Automated Builds tagging
  • Some questions of Docker -p and Dockerfile
  • logout/login from inside Vagrantfile
  • docker COPY not working when deploying with docker-machine
  • Containerized Kafka client errors when producing messages to the host Kafka server
  • Configure Postgres application users with Terraform for RDS
  • How do I debug a kube-proxy that's only proxying portal IP traffic to localhost and not other instances?
  • Login docker container get return info:cannot set user id: Resource temporarily unavailable
  • OPENSHIFT V3 : Issue with preStop container hook (with a basical example)
  • Is there any definitive guide on how to pass all the arguments to Docker containers while starting a container through kubernetes?
  • How to export a project from IBM Bluemix PaaS to anywhere else as a Docker?
  • 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.