Docker in LXC with kvm plugin AppArmor issue

  • Is anyone successfully running Docker inside an LXC container made with the KVM plugin? My test lxc container (Debian 12) runs into this Read-only file system error when doing a docker run:

    Code
    docker: Error response from daemon: AppArmor enabled on system but the docker-default profile could not be loaded: running `/usr/sbin/apparmor_parser apparmor_parser -Kr /var/lib/docker/tmp/docker-default2194068202` failed with output: apparmor_parser: Unable to replace "docker-default".  Unknown error (30): Read-only file system

    The only way I can get it working is uninstalling AppArmor inside the container.


    But when I use lxc-create to make a similar Debian 12 container (based on the same image), then I don't need to remove AppArmor in order to get docker working. I've noticed the fs mounts look very different compared to creating a similar container using lxc-create.


    The LXC container XML looks like this:



    These are my installation steps:


    Compared to lxc-create:

    I had to comment the AppArmor settings in /var/lib/lxc/test/config since AppArmor is not installed on the OMV host. But I didn't have to uninstall it inside the container. As you can see the mounts made by lxc and libvirt are very different... E.g. the read-only securityfs on /sys/kernel/security which seems to be the problem in libvirt lxc does not exists in the container made with lxc-start.


    Is it possible to get docker working in the LXC container made with the KVM plugin without uninstalling AppArmor inside the container?

    • Official Post

    Is anyone successfully running Docker inside an LXC container made with the KVM plugin?

    Why is the only question I have?

    But when I use lxc-create to make a similar Debian 12 container (based on the same image), then I don't need to remove AppArmor in order to get docker working.

    lxc-create and libvirt are evidently doing different things.

    Is it possible to get docker working in the LXC container made with the KVM plugin without uninstalling AppArmor inside the container?

    Not with the way libvirt is creating the lxc container. I honestly don't know why you are doing this though. Running a container in a container is something I don't want to make changes for.

    omv 7.7.10-1 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.2 | kvm 7.1.8 | compose 7.6.10 | cterm 7.8.7 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.3.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thanks for replying! I'm actually asking for a different setup (not OMV) where there's only libvirt available (and no docker). Since OMV has the KVM plugin and a community of libvirt users I was wondering if there was already some 'magic' going on in the plugin to make this work. But I was able to reproduce my issue also on OMV so now I'm wondering if anyone here ran into this (and found a solution). Not asking to make changes, but looking for advice/experience.

    • Official Post

    Ah. I would run containers in a VM instead of LXC in that situation. Since libvirt is doing so much of the LXC setup, I'm not even sure where to start to look for how to change it. On the other hand, I don't see an issue with removing apparmor if the containers are not on the internet.

    omv 7.7.10-1 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.2 | kvm 7.1.8 | compose 7.6.10 | cterm 7.8.7 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.3.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Thanks! A VM is what I'm trying to avoid actually :)


    I noticed that inside the lxc-create container the output of docker info shows:


    Security Options:

    seccomp

    Profile: builtin

    cgroupns


    So AppArmor is not enabled there by default.


    On the container made with kvm plugin (libvirt) docker info shows:


    Security Options:

    apparmor

    seccomp

    Profile: builtin

    cgroupns


    There it tries to use AppArmor, which it can't due to /sys/kernel/security being mounted read-only. So in order to make the libvirt container behave like the lxc-create container I just found out I can run:


    umount /sys/kernel/security && systemctl restart docker


    Then docker info will no longer list apparmor and docker run hello world works.


    So I think I have to look for a way to avoid /sys/kernel/security being mounted in the first place...

    • Official Post

    A VM is what I'm trying to avoid actually

    Any reason why?


    So I think I have to look for a way to avoid /sys/kernel/security being mounted in the first place...

    It is probably baked into the images the plugin is downloading.

    omv 7.7.10-1 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.2 | kvm 7.1.8 | compose 7.6.10 | cterm 7.8.7 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.3.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • I'm trying to avoid a VM so I can have direct access to the files on the host system using bind mounts (although maybe 9pfs could work, haven't tried yet). And I prefer not to have to pre-allocate RAM.


    I don't think it is baked in the image though. Even when using the same rootfs (created from the Debian LXC image from linuncontainers.org), the behavior is different when starting with lxc-start or virsh. Only in the second instance the /sys/kernel/security is mounted.

    • Official Post

    I don't think it is baked in the image though. Even when using the same rootfs (created from the Debian LXC image from linuncontainers.org), the behavior is different when starting with lxc-start or virsh. Only in the second instance the /sys/kernel/security is mounted.

    It was just a guess. I haven't looked into it.

    omv 7.7.10-1 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.2 | kvm 7.1.8 | compose 7.6.10 | cterm 7.8.7 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.3.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

  • Admittedly a very ugly hack, but I created an empty directory to be mounted at /sys/kernel/security and added this to the XML config:


    Code
        <filesystem type='mount' accessmode='mapped'>
          <source dir='/empty/'/>
          <target dir='/sys/kernel/security'/>
        </filesystem>


    Now docker doesn't complain, and runs without trying to use AppArmor and I didn't need to modify the image or manually uninstall AppArmor.


    The full XML looks like this:


  • Not with the way libvirt is creating the lxc container. I honestly don't know why you are doing this though. Running a container in a container is something I don't want to make changes for.


    I follow a youtube channel called @scottibyte and he explains as others have that a lxc container uses up less resources than a vm. He use docker within a lxc container a lot, I do understand to some extent why he does it.


    I've not tried it yet, as I've not seen many posts on here regarding lxc, which to me says either it's a little harder than using bare metal ubuntu and lxc, or people really just want to use docker an vms, which is pretty easy to do.


    The scottibyte channel is a good jumping in place to consider using lxc, very well put together tutorials. Plus I believe lxc is extremely popular with proxmox.


    I might actually have a go with my test vm for OMV and see what I can accomplish, probably more in the autumn/winter though, as I expect it might become a bit of a rabbit warren once I start playing with it :)

    OMV Version 7.latest | AMD Ryzen 5600G with 64GB | JBOD EXT4 & BRTFS

    Various Unifi router & switches | Only Linux laptops and PC's

    • Official Post

    he explains as others have that a lxc container uses up less resources than a vm.

    It does.

    He use docker within a lxc container a lot, I do understand to some extent why he does it.

    I believe lxc is extremely popular with proxmox.

    lxc is popular because there is no other container option in proxmox. People use docker in lxc for this reason. If proxmox had a native docker option, I doubt people would use lxc for docker. Since OMV has an option for VMs, LXC, and docker, there is very little reason to combine any of those.

    omv 7.7.10-1 sandworm | 64 bit | 6.11 proxmox kernel

    plugins :: omvextrasorg 7.0.2 | kvm 7.1.8 | compose 7.6.10 | cterm 7.8.7 | cputemp 7.0.2 | mergerfs 7.0.5 | scripts 7.3.1


    omv-extras.org plugins source code and issue tracker - github - changelogs


    Please try ctrl-shift-R and read this before posting a question.

    Please put your OMV system details in your signature.
    Please don't PM for support... Too many PMs!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!