Accessing the host device inside a container
From Docker 1.2 onwards, we can give access of the host device to a container with the --device
option, following the run
command. Earlier, you had to bind-mount it with the -v
option, and that had to be done with the --privileged
option.
Getting ready
Ensure that the Docker daemon is running on the host and can be connected through the Docker client. You will also need a device to pass the container to.
How to do it...
You can give access of a host device to the container using the following syntax:
docker container run --device=<Host Device>:<Container Device Mapping>:<Permissions> [OPTIONS] IMAGE [COMMAND] [ARG...]
Here is an example of using the preceding command:
$ docker container run --device=/dev/sdc:/dev/xvdc \ -i -t ubuntu /bin/bash
How it works...
The preceding command will access /dev/sdc
inside the container.
See also
Look at the help
option of docker container run
:
$ docker container run --help
The documentation on...