Ubuntu in Ubuntu. How to configure LXC

LXC – is a good solution to get a stateful isolated environment.


apt-get update
apt-get install lxd


  • Before start:
lxd init

Confirm each question by default value. You can choose Name of the storage backend to use (btrfs, dir, lvm) [default=btrfs]: dir to save files in a directories instead of lvm or image. It’s better to sync files.

  • List remote repositories. Ensure that you have an external URLs.
lxc remote list
|      NAME       |                   URL                    |   PROTOCOL    | AUTH TYPE | PUBLIC | STATIC |
| images          | https://images.linuxcontainers.org       | simplestreams |           | YES    | NO     |
  • List images in repo:
lxc image list images:

You can grep any images that you prefer. For example:

lxc image list images: | grep 'ubuntu.*18.04.*amd64'


  • Launch an image called ubuntu01 from template ubuntu/18.04:
lxc launch images:ubuntu/18.04 ubuntu01
  • List running containers:
lxc list
  • Enter into the container:
lxc exec ubuntu01 -- /bin/bash

So now you can work inside your new container. You can install and configure apps, etc.

If you are using a dir as a storage backend, you can access to container files here: /var/lib/lxd/containers/


  • Attach drive:
lxc config device add ubuntu01 srv disk source=/mnt/storage/srv/data/ path=/srv
  • Run privileged (root=root) without uid shifting to 100000 :
lxc config set ubuntu01 security.privileged true
  • Configure net for lxdbr0:
lxc network show lxdbr0
lxc network set lxdbr0 ipv4.address

or create a new one:

lxc network create lxdbr0 ipv6.address=none ipv4.address= ipv4.nat=true

assign an IP address for a container:

lxc network attach lxdbr0 ubuntu01 eth0
lxc config device set ubuntu01 eth0 ipv4.address
Tagged with:

Leave a Reply

Your email address will not be published.