使用Docker RUN命令创建的文件夹不断消失

时间:2017-10-17 15:47:58

标签: docker dockerfile

Dockerfile内容:

# Setup directory structure
RUN mkdir -p /dev/log/ \
 && touch /dev/log/placeholder.file \
 && ls -la /dev/

如下所示,在/dev/log/输出中可见后,docker build文件夹在实际容器中明显丢失。它在哪里? /dev/是否被视为特殊文件夹?

docker build输出:

Step 13/14 : RUN mkdir -p /dev/log/  && touch /dev/log/placeholder.file  && ls -la /dev/
 ---> Running in ac5014b75a54
total 4
drwxr-xr-x 6 root root  360 Oct 17 15:04 .
drwxr-xr-x 1 root root 4096 Oct 17 15:04 ..
lrwxrwxrwx 1 root root   11 Oct 17 15:04 core -> /proc/kcore
lrwxrwxrwx 1 root root   13 Oct 17 15:04 fd -> /proc/self/fd
crw-rw-rw- 1 root root 1, 7 Oct 17 15:04 full
drwxr-xr-x 2 root root   60 Oct 17 15:04 log
drwxrwxrwt 2 root root   40 Oct 17 15:04 mqueue
crw-rw-rw- 1 root root 1, 3 Oct 17 15:04 null
lrwxrwxrwx 1 root root    8 Oct 17 15:04 ptmx -> pts/ptmx
drwxr-xr-x 2 root root    0 Oct 17 15:04 pts
crw-rw-rw- 1 root root 1, 8 Oct 17 15:04 random
drwxrwxrwt 2 root root   40 Oct 17 15:04 shm
lrwxrwxrwx 1 root root   15 Oct 17 15:04 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root   15 Oct 17 15:04 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root   15 Oct 17 15:04 stdout -> /proc/self/fd/1
crw-rw-rw- 1 root root 5, 0 Oct 17 15:04 tty
crw-rw-rw- 1 root root 1, 9 Oct 17 15:04 urandom
crw-rw-rw- 1 root root 1, 5 Oct 17 15:04 zero
 ---> 2bdcd739e2c7
Removing intermediate container ac5014b75a54

从容器内部查看:

docker run -it --rm <container> /bin/bash

[root@moby dev]# ls -al
total 4
drwxr-xr-x 5 root root    360 Oct 17 15:19 .
drwxr-xr-x 1 root root   4096 Oct 17 15:19 ..
crw--w---- 1 root tty  136, 0 Oct 17  2017 console
lrwxrwxrwx 1 root root     11 Oct 17 15:19 core -> /proc/kcore
lrwxrwxrwx 1 root root     13 Oct 17 15:19 fd -> /proc/self/fd
crw-rw-rw- 1 root root   1, 7 Oct 17 15:19 full
drwxrwxrwt 2 root root     40 Oct 17 15:19 mqueue
crw-rw-rw- 1 root root   1, 3 Oct 17 15:19 null
lrwxrwxrwx 1 root root      8 Oct 17 15:19 ptmx -> pts/ptmx
drwxr-xr-x 2 root root      0 Oct 17 15:19 pts
crw-rw-rw- 1 root root   1, 8 Oct 17 15:19 random
drwxrwxrwt 2 root root     40 Oct 17 15:19 shm
lrwxrwxrwx 1 root root     15 Oct 17 15:19 stderr -> /proc/self/fd/2
lrwxrwxrwx 1 root root     15 Oct 17 15:19 stdin -> /proc/self/fd/0
lrwxrwxrwx 1 root root     15 Oct 17 15:19 stdout -> /proc/self/fd/1
crw-rw-rw- 1 root root   5, 0 Oct 17 15:19 tty
crw-rw-rw- 1 root root   1, 9 Oct 17 15:19 urandom
crw-rw-rw- 1 root root   1, 5 Oct 17 15:19 zero

1 个答案:

答案 0 :(得分:1)

  

/ dev /被视为特殊文件夹吗?

简短的回答,是的。这是一个特殊的文件夹,你不应该在那里存储东西。发生的事情是/dev被装载到容器运行时,这会覆盖你的文件夹:

$ docker run ubuntu mount | grep "/dev"
tmpfs on /dev type tmpfs (rw,nosuid,size=65536k,mode=755)

您需要选择另一个地方来存储文件或在运行时创建文件夹,以便在安装后发生。