Skip to content

created loop devices do not appear in container even when run privileged #27886

Description

Description

Mounting a loopback device in a container requires CAP=SYS_ADMIN or even better --privileged. However, the /dev/loop* do not appear in the container when created dynamically.

This is particularly a problem when manipulating disk .img files inside a container.

I am using ubuntu:16.04 as a base to reproduce, but this should be the same with any base.

Steps to reproduce the issue:

  1. docker run --rm -it --privileged ubuntu:16.04 bash
  2. In container: apt update && apt install -y gdisk
  3. In container: make a 500MB disk filedd if=/dev/zero of=/ofile.img bs=1M count=500
  4. In container: make partitions in the disksgdisk -n 1:2048:194559 -n 2:195560:300000 /ofile.img
  5. In container: scan file and create loop devices for partitions:losetup -f /ofile.img -P --show
  6. In container: see that partition files have not been createdls -l /dev/loop*
  7. In host: see that partition files _have* been created: ls -l /dev/loop*

Describe the results you received:
In container:

/dev/loop0
/dev/loop1
...

On host:

/dev/loop0
/dev/loop0p1
/dev/loop0p2
/dev/loop1
...

Essentially, when running --privileged, docker copies the /dev/ files over to the container, but does not keep them updated.

Same problem exists if you have the files before and then run losetup -D (on host or in container): on host the /dev/loop0p1 etc. files are gone, but linger in container.

Describe the results you expected:
When in privileged mode (or cap=sys_admin), since mounting is possible, devices should be synced up where relevant.

Output of docker version:

Docker version 1.12.1, build 23cf638

Output of docker info:

Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 735
Server Version: 1.12.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 365
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: null bridge host overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-42-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.674 GiB
Name: avi-Latitude-E6320
ID: SVT2:XSJY:6LYB:O4NB:NGZO:JTXJ:MVPZ:Z2BG:JOPO:IZXS:XD2M:5FCN
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
 127.0.0.0/8

Additional environment details (AWS, VirtualBox, physical, etc.):
Physical laptop running Ubuntu.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementEnhancements are not bugs or new features but can improve usability or performance.kind/question

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions