Can Debian Stretch run on Ubuntu 16.04 LTS via LXC/LXD?

There is this never ending flame wars about whether Debian or Ubuntu is better. My personal servers have been historically on Ubuntu LTS due to the fact that they are known to have more updated packages that Debian. As I was planning to try MariaDB’s Galera cluster, I found that Debian Stretch has a more recent version of MariaDB than Ubuntu 16.04LTS.

No problem! I’ll run MariaDB inside a Debian container rather than an Ubuntu’s one. Here’s how to proceed:

# We download and create a container based on debian/stretch and we’ll call the VM mariadb-1

lxc launch images:debian/stretch mariadb-1

# We install an SSH server inside the VM to access it

lxc exec mariadb-1 — apt-get install ssh

# I put my public key inside the VM so that I can SSH into it.

# But before that, we need to create the .ssh directory

lxc exec mariadb-1 — sh -c ‘mkdir -p /root/.ssh/’

lxc exec mariadb-1 — sh -c ‘echo “ssh-rsa AAAAB3N…+j/ nayar@macbook.local” > /root/.ssh/authorized_keys’

# The keys should be readable only by the owner

lxc exec mariadb-1 — sh -c ‘chmod -R 600 /root/.ssh/’

And now your container should be accessible via SSH. You can use it like a VM. You may use the command below to find it’s IP

lxc list

| mariadb-1     | RUNNING | (eth0)

Tips: If by doing so, the VM still asks you for password while trying to ssh on it, make sure you have properly pushed your ssh agent. On your laptop, try the following

ssh-add -k

ssh -A “ssh root@

Don’t repeat the same procedure for every container you need to create. Just copy from one:

lxc copy mariadb-1 mariadb-2

There you go. You have a new container under 5 seconds. Hope you liked this mini tutorial. Feel free to comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *