Zak
Zak

Reputation: 12653

Folder created with Docker RUN command keeps disappearing

Dockerfile contents:

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

As you can see below, the /dev/log/ folder is conspicuously missing from the actual container after being visible in the docker build output. Where is it going? Is /dev/ considered a special folder?

docker build output:

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

View from inside the container:

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

Upvotes: 0

Views: 407

Answers (1)

Andy Shinn
Andy Shinn

Reputation: 28523

Is /dev/ considered a special folder?

Short answer, yes. It is a special folder and you shouldn't store stuff there. What is happening is that /dev gets mounted at container runtime, which is overwriting your folder:

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

You will need to choose another place to store files or create the folder at runtime so that it happens after the mount.

Upvotes: 1

Related Questions