Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dockerfile: Persist symlink in RUN instruction

I am building a Docker image, and need to perform a symlink to avoid an error when later executing Python scripts.

I am performing this symlink with the following command in the Dockerfile:

RUN ln -s /dev/null /dev/raw1394

However, when later entering the image with an interactive shell, this symlink does not exist:

$ docker run -it docker_image /bin/bash root@789442c6ccf6:/# ls /dev/ console core fd full mqueue null ptmx pts random shm stderr stdin stdout tty urandom zero

If I run this symlink from inside the container, it works well.

How can I make this symlink persist across all layers of the image?

Thank you

like image 428
user7390416 Avatar asked Feb 01 '26 23:02

user7390416


1 Answers

For making files (in fact everything that is an inode) persistent you need to create a volume. In this special case (the /dev directory) it is most probably not possible because /dev is for system files.

But you probably know about the CMD command in a Dockerfile. This is the command that is executed to start your image. You could point to a shell script that will first create your link and then hand over execution to your code. This shell script has to be added to the image and needs to have the execute bit being set.

Like this in your Dockerfile:

ADD start.sh /
CMD /start.sh

And in start.sh:

#!/bin/sh

ln -s /dev/null /dev/raw1394
exec /your/binary_or_whatever
like image 93
itsafire Avatar answered Feb 04 '26 15:02

itsafire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!