Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to rsync from a host computer to docker container using docker cp

I am trying to run following:

  1. start a container in background

docker run -dit -p 8090:80 --name container repository:dockerfile bash

  1. I want to exclude sub directory /data from /test

docker cp /Users/$USER/test container:/test

  1. I thought of using rsync for this docker exec rsync -avP --exclude /Users/$USER/test/data /Users/$USER/test/ container:/test/

I get below error:

rsync: Failed to exec ssh: No such file or directory (2)
rsync error: error in IPC code (code 14) at pipe.c(85) [sender=3.1.0]
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(226)
[sender=3.1.0]

How do I rsync from host to container?

like image 277
Brenda Olivia Martis Avatar asked Aug 16 '17 22:08

Brenda Olivia Martis


Video Answer


1 Answers

The way to use rsync to copy files into a Docker container

Make sure your Docker container has rsync installed, and define this alias:

alias drsync="rsync -e 'docker exec -i'"

Now, you can use rsync with containers as if they are remote machines:

drsync -av /source/ container:/destination/
like image 84
Milo Chen Avatar answered Oct 01 '22 01:10

Milo Chen