sakura_liu
sakura_liu

Reputation: 269

How to mount a device of host to host in a Docker container?

I have a Linux host with a block device /dev/sdb , and I want to mount the device to host's /mnt/sdb.

My special need is that do this in a container but not in the host itself, and need not to mount the device into container also (for example -v).

For example (does not work certainly):

$ docker run some-image mount /dev/sdb /mnt/sdb

Or absolutely this is impossible?

Upvotes: 10

Views: 25785

Answers (2)

Martin
Martin

Reputation: 3114

Docker supports adding/passing through devices to a container:

docker run --device=/dev/sdb

https://docs.docker.com/engine/reference/commandline/run/#add-host-device-to-container-device

Upvotes: 10

VonC
VonC

Reputation: 1324003

You should be able to mount that device (outside docker), and then use said mounted folder in your docker run.
See issue 21485 as an illustration:

mount /dev/sdb /workspace
docker run --rm -v "/workspace:/workspace" some-image

Upvotes: 2

Related Questions