https://docs.docker.com/storage/volumes/#backup-restore-or-migrate-data-volumes

  
$ docker run --rm --volumes-from dbstore -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /dbdata  

???

Real Demo Example:

mongo cantainer

 mongo:  
    image: mongo  
    #restart: always  
    environment:  
      MONGO_INITDB_ROOT_USERNAME: root  
      MONGO_INITDB_ROOT_PASSWORD: example  
    volumes:  
      - alldata:/data/db  
    networks:  
      - fastdev

volumes is /data/db
docker running name is testbackup_mongo_1_1c9e49740f2e (this use docker ps check your run time docker name. Don’t copy)

run

  
$ docker run --rm --volumes-from testbackup_mongo_1_1c9e49740f2e -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /data/db  

ls -al can see backup.tar

README:

1. use ubuntu container link to mongo
2. mount $(pwd) path to ubuntu inside /backup directory. $(pwd) run command at path.
3. tar cvf “put where & filename” “what data be tar”, So “put where & filename”=/backup/backup.tar “what data be tar”=/data/db
/data/db be tar write to backup.tar in /backup, then /backup be mount to $(pwd), you can see backup.tar put run command path.