Run Docker inside a LXD Container

Problem

Was trying to ran a docker container inside a LXD container. Got the error below:

OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused

Solution

  • First create a storage pool named dockerPool and use the btrfs storage backend that docker supports natively:
$  lxc storage create dockerPool btrfs
Storage pool dockerPool created
  • Then create a new container based on 20.04 and call it demo:
$  lxc launch images:ubuntu/20.04 demo
Creating demo
Starting demo
  • Then create a new storage volume named dockerVol for the docker storage pool above:
$ lxc storage volume create dockerPool dockerVol
Storage volume dockerVol created
  • Then attach it to the demo container. The device of type disk being created is called dockerDevice. The source pool has the same name docker and the source volume is called demo:
$ lxc config device add demo dockerDevice disk pool=dockerPool source=dockerVol path=/var/lib/docker
Device dockerDevice added to demo
  • Finally make the config changes below:
$ lxc config set demo security.nesting=true security.syscalls.intercept.setxattr=true security.syscalls.intercept.mknod=true
  • Then restart the demo container:
$ lxc restart demo

References

Docker cannot write to devices.allow

Running Docker inside of a LXD container