Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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?

like image 604
sakura_liu Avatar asked Aug 03 '16 06:08

sakura_liu


People also ask

How do I connect to a Docker container from outside the host on the same network window?

Map TCP port 80 in the container to port 8080 on the Docker host for connections to host IP 192.168. 1.100. Map UDP port 80 in the container to port 8080 on the Docker host. Map TCP port 80 in the container to TCP port 8080 on the Docker host, and map UDP port 80 in the container to UDP port 8080 on the Docker host.

How do you expose host ports to containers?

You can expose a port through your Dockerfile or use --expose and then publish it with the -P flag. This will bind the exposed port to your Docker host on a random port (verified by running docker container ls ). You can expose a port through your Dockerfile or use --expose and then publish it with the -p 80:80 flag.


2 Answers

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

like image 81
Martin Avatar answered Sep 21 '22 01:09

Martin


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
like image 32
VonC Avatar answered Sep 21 '22 01:09

VonC