2

The following lsblk command returns "null" for several fields when called from within my archlinux container. On my natively running system the lsblk command returns values for all fields as expected.

lsblk --json -b -o+partn,partuuid,parttype,uuid /dev/sdd

Here's my docker run command.

docker run \
    --env PS1="mycontanier(\#)[\d \T:\w]\\$ " \
    --interactive \
    --privileged \
    --device=/dev/sdd \
    --cap-add=SYS_ADMIN \
    --rm \
    --tty \
    "mycontainer:latest"

And here's my Dockerfile

FROM docker.io/archlinux:latest

ENV NAME=mycontainer VERSION=rolling

RUN pacman -Sy --noconfirm
git
dosfstools
arch-install-scripts
reflector
python-archinstall
rsync
pkgconf

RUN pacman -Scc --noconfirm

Configure reflector

RUN reflector
--latest 5
--protocol http,https
--save "/etc/pacman.d/mirrorlist"
--sort rate

CMD /usr/bin/bash

What should I modify about my container to make these lsblk report the correct values for my drive?

Giacomo1968
  • 58,727
Raven
  • 209

1 Answers1

0

I quote the accepted answer from the post
How to access block device inside a Docker container.

For hardware device, you will need to give capabilities to container to operation the device, there are 2 options here:

Option 1: Use privileged

See Full container capabilities (--privileged):

# docker container run --rm --privileged --name c1 -it --mount type=bind,source=/dev/sdb,target=/data centos
[root@7ab2eaef67cd /]# ls -al /data
brw-rw---- 1 root disk 8, 16 Sep  3 08:13 /data
[root@7ab2eaef67cd /]# dd if=/dev/zero of=/data bs=1 count=1
1+0 records in
1+0 records out
1 byte copied, 0.00710505 s, 0.1 kB/s
[root@7ab2eaef67cd /]# exit

Option 2: Use --device

See Add host device to container (--device):

# docker container run --rm --name c1 -it --device=/dev/sdb:/data centos
[root@3a05b15b3b96 /]# ls -al /data
brw-rw---- 1 root disk 8, 16 Sep  3 08:15 /data [root@3a05b15b3b96 /]# dd if=/dev/zero of=/data bs=1 count=1
1+0 records in
1+0 records out
1 byte copied, 0.00326708 s, 0.3 kB/s
[root@3a05b15b3b96 /]# exit
harrymc
  • 498,455