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

Dockerfile内容:

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

正如你在下面看到的那样,在docker build输出中可见之后, /dev/log/文件夹在实际容器中显然缺less。 去哪里? /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 

/ dev /被认为是一个特殊的文件夹?

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

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

您需要select另一个位置来存储文件,或者在运行时创build文件夹,以便在安装后进行。