docker-copy-volume.sh
· 499 B · Bash
Bruto
#!/bin/bash
# Check if the required arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <volume_id> <destination>"
exit 1
fi
# Assign arguments to variables
volume_id=$1
destination=$2
# Create a temporary container to mount the volume
container_id=$(docker create -v $volume_id:/source_data --name temp_container busybox)
# Copy the data from the volume to the destination
docker cp $container_id:/source_data $destination
# Remove the temporary container
docker rm $container_id
| 1 | #!/bin/bash |
| 2 | |
| 3 | # Check if the required arguments are provided |
| 4 | if [ $# -ne 2 ]; then |
| 5 | echo "Usage: $0 <volume_id> <destination>" |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
| 9 | # Assign arguments to variables |
| 10 | volume_id=$1 |
| 11 | destination=$2 |
| 12 | |
| 13 | # Create a temporary container to mount the volume |
| 14 | container_id=$(docker create -v $volume_id:/source_data --name temp_container busybox) |
| 15 | |
| 16 | # Copy the data from the volume to the destination |
| 17 | docker cp $container_id:/source_data $destination |
| 18 | |
| 19 | # Remove the temporary container |
| 20 | docker rm $container_id |
| 21 |