I been trying to create a bind mount on my docker container, but the files in the bind mount are missing. I think it might have something to do with permission or ownership of files?
I created a store_log
dir and there are some files in it. create my bind mount with --mount
option, set destination to /app/logs
. set container to sleep so I can go inside to debug it
ip-10-249-9-40:store_log buildkite-agent$ ls -la .
total 16
drwxr-xr-x 4 buildkite-agent admin 128 Jul 18 00:19 .
drwxr-xr-x 23 root admin 736 Jul 18 00:19 ..
-rwxrwxrwx 1 root wheel 8064 Jul 18 00:19 bk-job-log
-rw-rw-rw- 1 buildkite-agent admin 0 Jul 18 00:19 foo.txt
ip-10-249-9-40:store_log buildkite-agent$ pwd
/my/path/store_log
ip-10-249-9-40:store_log buildkite-agent$ docker run --mount type=bind,source=/my/path/store_log,target=/app/logs my_image sleep 1000
go inside the container. nothing is under the /app/logs
folder….
ip-10-249-9-40:~ buildkite-agent$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e13cbc0a54c9 my_image "sleep 1000" 11 seconds ago Up 11 seconds festive_volhard
ip-10-249-9-40:~ buildkite-agent$ docker exec -it e13cbc0a54c9 /bin/bash
root@e13cbc0a54c9:/app# ls
config.json logs retriable_error_function.py
root@e13cbc0a54c9:/app# cd logs
root@e13cbc0a54c9:/app/logs# ls -la
total 8
drwxr-xr-x 2 root root 4096 Jul 18 00:27 .
drwxr-xr-x 1 root root 4096 Jul 18 03:09 ..
-rw-r--r-- 1 root root 0 Jul 18 00:27 from_docker.txt
root@e13cbc0a54c9:/app/logs#
the from_docker.txt
is a file I created from inside container (another container) but seems to have persisted which is weird because I though unlike volume bind mount does not persist?
Another weird behavior is that if I try to mount say /bin
to /app/bin
then it will work
ip-10-249-9-40:store_log buildkite-agent$ ls -la /bin
total 9584
drwxr-xr-x@ 39 root wheel 1248 Jun 15 2023 .
drwxr-xr-x 20 root wheel 640 Jun 15 2023 ..
-r-xr-xr-x 1 root wheel 1326752 Jun 15 2023 bash
-rwxr-xr-x 1 root wheel 135408 Jun 15 2023 cat
-rwxr-xr-x 1 root wheel 136960 Jun 15 2023 chmod
-rwxr-xr-x 1 root wheel 152800 Jun 15 2023 cp
-rwxr-xr-x 2 root wheel 1153408 Jun 15 2023 csh
-rwxr-xr-x 1 root wheel 307248 Jun 15 2023 dash
-rwxr-xr-x 1 root wheel 168032 Jun 15 2023 date
-rwxr-xr-x 1 root wheel 185088 Jun 15 2023 dd
-rwxr-xr-x 1 root wheel 151440 Jun 15 2023 df
...
ip-10-249-9-40:store_log buildkite-agent$ docker run --mount type=bind,source=/bin,
target=/app/bin my_image sleep 1000
ip-10-249-9-40:~ buildkite-agent$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
925768a338cb myu_image "sleep 1000" 5 seconds ago Up 5 seconds angry_bardeen
ip-10-249-9-40:~ buildkite-agent$ docker exec -it 925768a338cb /bin/bash
root@925768a338cb:/app# ls /bin
addpart infocmp rmdir
apt infotocap run-parts
apt-cache install runcon
apt-cdrom ionice savelog
apt-config ipcmk script
apt-get ipcrm scriptlive
apt-key ipcs scriptreplay
apt-mark ischroot sdiff
...
root@925768a338cb:/app#
any ideas?
edit
maybe worth mentioning this is on a remote machine, the default user is buildkite-agent
and the user in container is root
. I have tried changing container user with --volume /etc/passwd:/etc/passwd:ro --volume /etc/group:/etc/group:ro --user "$(id -u):$(id -g)"
but that doesn’t seem to help
1