
따라해보려고 해요이 기사매우 간단한 rsync 데몬 Docker 컨테이너를 실행하는 데 문제가 있습니다. rsync 데몬을 포함하여 모든 것이 루트로 실행되어야 함에도 불구하고 파일 수신에 실패하고 오류 13 권한이 거부되었습니다. 여기서는 문제를 쉽게 재현할 수 있도록 간단한 예를 준비했으며, 문제를 재현하는 데 네트워킹이 필요하지도 않습니다.
❯ cat rsync_daemon.Dockerfile
FROM alpine
RUN apk add --no-cache rsync \
&& mkdir -p /opt/share \
&& echo "testcontent" > /opt/share/testfile \
&& echo "[share]" > /etc/rsyncd.conf \
&& echo "path = /opt/share" >> /etc/rsyncd.conf \
&& echo "hosts allow = *" >> /etc/rsyncd.conf \
&& echo "read only = false" >> /etc/rsyncd.conf
CMD rsync --daemon --port 9999 && while sleep 1; do /bin/true; done
❯ mkdir context # create empty dir to use as docker context
❯ docker build -t rsync_manual -f rsync_daemon.Dockerfile context
빌드 프로세스는 사고 없이 진행되며 준수되었음을 확인할 수 있습니다.
docker run -d --rm --name rsyncd_manual rsync_manual
분리된 컨테이너가 정상적으로 실행되고 시작됩니다.
docker exec -it rsyncd_manual sh
이는 대화형 셸을 컨테이너에 삽입한 다음 테스트합니다. 데몬에서는 문제가 없지만 데몬이 파일을 받을 수 없습니다.
/ # ls -la /opt/
total 12
drwxr-xr-x 1 root root 4096 Sep 30 02:21 .
drwxr-xr-x 1 root root 4096 Sep 30 02:22 ..
drwxr-xr-x 2 root root 4096 Sep 30 02:21 share
/ # ls -la /opt/share/
total 12
drwxr-xr-x 2 root root 4096 Sep 30 02:21 .
drwxr-xr-x 1 root root 4096 Sep 30 02:21 ..
-rw-r--r-- 1 root root 12 Sep 30 02:21 testfile
/ # ls
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
/ # rsync -r rsync://localhost:9999/share dest
/ # ls -la dest
total 12
drwxr-xr-x 2 root root 4096 Sep 30 02:23 .
drwxr-xr-x 1 root root 4096 Sep 30 02:23 ..
-rw-r--r-- 1 root root 12 Sep 30 02:23 testfile
/ # cat dest/testfile
testcontent
/ # mkdir src
/ # echo 'testdata' > src/testdata
/ # rsync -r src rsync://localhost:9999/share
rsync: [generator] recv_generator: mkdir "/src" (in share) failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1327) [sender=3.2.5]
/ # ps aux
PID USER TIME COMMAND
1 root 0:00 /bin/sh -c rsync --daemon --port 9999 && while sleep 1; do /bin/true; done
8 root 0:00 rsync --daemon --port 9999
79 root 0:00 sh
1382 root 0:00 sleep 1
1383 root 0:00 ps aux
무슨 일이 일어나고 있는지 아는 사람 있나요?
답변1
응, 이거 이상해...
chmod g+w /opt/share/
그것이 작동하도록 허용하십시오. 하지만 다른 테스트(호스트의 디렉터리를 rsync 데몬 공유에 바인딩하는 위의 테스트보다 약간 덜 단순화됨)에서는 이렇게 해야 합니다 chmod o+w
!
/opt/share/
내가 알고 싶은 것은 Perms rsync가 있을 때 왜 쓸 수 없는가입니다 drwxr-xr-x
. rsync
내가 아는 한 Rsync는 루트로 실행됩니다. 내가 이렇게 말하는 것이 틀렸는가?