LXD with Docker

I would like to first say I am not a fan of docker however as a developer from time to time using docker in LXD containers helps with testing prebuilt docker images quickly.

I thought I would share my recent experience setting up docker in an LXD environment on an Ubuntu 18.04 image.

Below are the instructions I used to get a docker image running with full internet access.

lxc launch ubuntu:18.04 dex2 -c security.nesting=true

lxc exec dex2 bash

sudo apt-get update && sudo apt-get upgrade

sudo apt install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

sudo apt update

apt-cache policy docker-ce

sudo apt install docker-ce

sudo systemctl status docker

docker run hello-world

1 Like

We are also running Docker inside an LXC container in our development workloads and some of our production workloads like this.

“security.nesting=true” this will work and docker can load with low level kernel modules.

But if you want other kernel level features like “overlay”,“iptables”,“br_netfilter” (in case you want to run docker-swarm/Kubernetes inside an LXC containers). Docker will struggle to start and then you need to add these features to your Container Config Object.

:thinking: Good to know!