Salvatore D'angelo
Salvatore D'angelo

Reputation: 1149

Is it possible see volume in Docker as device?

I have a script used in production that does basically this:

make.ext4 ... /dev/sdb1
mount /dev/sdb1 /folder
and so on

I have a Docker environment where I simulate my production environment. Now, what I need is the possibility to use the same script on both the env. To do that, I need the possibility in Docker to have a /dev/sdb1 device and attach on it a volume in some way, so that when I run the commands above my volume is attached to /folder.

I know this can be done easily with:

docker run -t <tag> -v <my volume>:/folder -it /bin/bash

But in this way, things are a little different in Docker container and I need to modify my script (In my case I have several scripts to change).

Is there a way to do something like:

docker run -t <tag> -v <my volume>:/dev/sdb1 -it /bin/bash

so that when in Docker I do:

mount /dev/sdb1 /folder

I mount my external volume to /folder in the container?

Upvotes: 0

Views: 106

Answers (1)

Alejandro Galera
Alejandro Galera

Reputation: 3691

Have you tried to run docker with privileges to do mount?

Maybe if you launch docker run --privileged or docker run --cap-add=SYS_ADMIN, you have /dev/sdb1 accessible from docker, so, is possible to do mount /dev/sdb1/

For further information about docker container privileges, please, see: Docker Documentation privileged mode and capabilities

Upvotes: 1

Related Questions