Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created November 12, 2019 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanbekker/8276ecb5697ec352be0085c96b4cf33e to your computer and use it in GitHub Desktop.
Save ruanbekker/8276ecb5697ec352be0085c96b4cf33e to your computer and use it in GitHub Desktop.
How to run Docker in a LXC Container using LXD

Provision a LXC Container:

container_name=jenkins-docker-node-01

lxc init images:debian/10/cloud $container_name
lxc config set $container_name limits.memory 2048MB
lxc config set $container_name security.privileged true
lxc config set $container_name security.nesting true
lxc config set $container_name security.privileged true

cat <<EOT | lxc config set $container_name raw.lxc -
lxc.cgroup.devices.allow = a
lxc.cap.drop =
EOT

lxc start $container_name

Install Docker:

$ apt update
$ apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common -y
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
$ add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
$ apt update
$ apt install docker-ce -y
$ systemctl enable docker
$ systemctl restart docker

Run a Container:

$ docker run -it busybox cat /etc/hostname
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
0f8c40e1270f: Already exists
Digest: sha256:1303dbf110c57f3edf68d9f5a16c082ec06c4cf7604831669faf2c712260b5a0
Status: Downloaded newer image for busybox:latest
baf4e8bc36a0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment