Skip to content

Instantly share code, notes, and snippets.

@hesoyamcode
Last active July 21, 2019 18:12
Show Gist options
  • Save hesoyamcode/ad9cccb1d13ceea910780574b0723f3f to your computer and use it in GitHub Desktop.
Save hesoyamcode/ad9cccb1d13ceea910780574b0723f3f to your computer and use it in GitHub Desktop.
docker command copy from/to docker local (server it self)
The cp command can be used to copy files. One specific file can be copied like:
SQL
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
MONGO
#backup specific database
mongodump --out /mongo-backup-dir/ -d mywishes_production
#backup all database
mongodump --out /mongo-backup-dir/
docker cp foo.txt mycontainer:/foo.txt
docker cp mycontainer:/foo.txt foo.txt
For emphasis, mycontainer is a container ID, not an image ID.
Multiple files contained by the folder src can be copied into the target folder using:
docker cp src/. mycontainer:/target
docker cp mycontainer:/src/. target
copy from server to local computer
scp username@remoteHost:/remote/dir/file.txt /local/dir/
To copy all from Local Location to Remote Location (Upload)
scp -r /path/from/destination username@hostname:/path/to/destination
To copy all from Remote Location to Local Location (Download)
scp -r username@hostname:/path/from/destination /path/to/destination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment