I am trying to run following: start a container in background docker run -dit -p 8090:80 --name container repository:dockerfile bash I want to exclude sub directory /data from /test docker cp /Users/$USER/test container:/test 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? sauerburger5,0434 gold badges33 silver badges45 bronze badges asked Aug 16, 2017 at 22:23 Map the host directory first, into the container: docker run -v /Users/$USER/test:/temp-test -dit -p 8090:80 --name container repository:dockerfile bash Then use the rsync as follows: docker exec container rsync -avP --exclude /temp-test/data /temp-test/ /test/ answered Aug 17, 2017 at 1:14 RobertRobert35.9k8 gold badges94 silver badges98 bronze badges 0 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/ answered Nov 13, 2020 at 4:34 Milo ChenMilo Chen3,9154 gold badges22 silver badges38 bronze badges 3 When you run docker exec rsync [...] you execute the rsync command in your container. The path /Users/$USER/test/ corresponds to a directory on you host system, so rsync has a hard time finding it in your container. There are basically two ways to use rsync to transfer files into a container: You can install an ssh server on you host system and use rsync to connect from within your container to the host system from the outside. If you have a running ssh server on you host and the host is reachable under the name host you can do docker exec rsync -avP --exclude /Users/$USER/test/data host:/Users/$USER/test /test You can install an ssh server inside the container and use rsync on your host system to connect to the container from the outside. I assume your container is reachable under the name container, then you can do rsync avP --exclude /Users/$USER/test/data /Users/$USER/test container:/test In this case you have to make sure that the ssh port (default is 22) is published by the docker daemon. answered Aug 16, 2017 at 22:57 sauerburgersauerburger5,0434 gold badges33 silver badges45 bronze badges 2 The rsync: Failed to exec ssh: No such file or directory (2) is caused because ssh is not installed for you container. You install it manual or add it to your requirements file to install it automaticly. answered Aug 23, 2018 at 12:01