Rsync fails on container

Long story short:
I need to rsync data from docker container that does not have rsync (docker cp is in efficient in this case).
The image used for this container does not have rsync AND i cannot modify the image.
Hence, I compiled static rsync. It works well but fails when used in container as follwoing:

$ docker ps
CONTAINER ID   IMAGE          COMMAND                  CREATED        STATUS        PORTS                               NAMES
0fc140e45de5   95be0e9baa70   "nginx -g 'daemon of…"   16 hours ago   Up 16 hours>80/tcp, :::80->80/tcp   affectionate_chatterjee

$ rsync -e 'docker exec -i' -av 0fc140e45de5:/etc/passwd /tmp/test/
receiving incremental file list
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(235) [Receiver=3.1.3]

Maybe, docker/container requires some tune up to run rsync?

I understand that you cannot modify the image, but is the container in an offline environment without internet connection? If it isn’t, you could install rsync instead of compiling it. If you need to compile it, do it in a container based on the same image that the other container is based on. Different distributions can have different libraries so when you copy the result it can work differently.

If you rdata is on a volume, you can also mount that volume in a new container that has rsync.

If it is a local volume, you can rsync /var/lib/docker/volumes/<volumename>/_data as root on your host. I usually don’t recommend it, because it is under /var/lib/docker but it is at least not on an overlay filesystem.

Hi Rimelek,
Thank you very much for reply.

  1. Yes, that is isolated environment - no internet connection :frowning:
  2. rsync is compiled (statically) on the same distribution but not in container out of theimage (I could give it a try though. Im a bit desperated here :wink: )
  3. volume/local volume - i have never tried that but that could be an idea. (for the moment data are on a local volume but finally there will be dedicated volume).
    Do u have any (simple) example how to access local volume?
    This is what I see on the host:
# ls -al /var/lib/docker/volumes/
total 32
drwx-----x  2 root root   4096 Aug 16 15:07 .
drwx--x--- 13 root root   4096 Aug 16 15:07 ..
brw-------  1 root root 253, 0 Aug 16 15:07 backingFsBlockDev
-rw-------  1 root root  32768 Aug 16 15:07 metadata.db

I have found files under /var/lib/docker/overlay2/

# ls -al /var/lib/docker/overlay2/2a49eb5a22e9f422a66fbc9bc49ce06c4fb4635a5282c8935ad64a749708031e/diff/
total 48
drwxr-xr-x 10 root root 4096 Aug 17 06:59 .
drwx--x---  5 root root 4096 Aug 16 15:11 ..
drwxr-xr-x 16 root root 4096 Aug 16 16:18 a
drwxr-xr-x  3 root root 4096 Aug 16 16:17 b
drwxr-xr-x  2 root root 4096 Aug 17 06:59 home
drwx------  2 root root 4096 Aug 16 15:12 root
drwxr-xr-x  2 root root 4096 Aug 16 15:11 run
drwxrwxrwt  2 root root 4096 Aug 17 07:22 tmp
drwxr-xr-x  3 root root 4096 May 31 15:42 usr
drwxr-xr-x  4 root root 4096 Jun 29 12:19 var

It looks like you don’t have a local volume. Maybe you just have a bind mount which you can see on your host without going into the docker data folder. In that case I can’t tell you where that folder is, but you can use docker container inspect on your container to find that out.

This is what you should never modify. You could read it, but since it is either the filesystem of the container or an image layer, I would not use it. If this is where your data is, then you wrote it on the container’s filesystem which is not recommended.