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?

  • How to give my desktop Ubuntu machine's user full permissions to a docker volume, in addition to TWO users within the docker container?
  • Allow more memory when docker build a Dockerfile
  • How can I install docker on Debian 8 kernel 2.6.32
  • how to connect Docker containers without a bridge?
  • How do docker containers resolve hostname of other docker containers running on the same machine?
  • Deploy NoneJS application with Docker
  • Why does boot2docker ip fail?
  • Accessing services on the Docker host
  • What is the easiest method to copy files and directories in dockerfile
  • Docker memory limit in pipelines
  • php composer with docker build: failed to clone git
  • Using docker-compose volumes_from option does not work
  • 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.