LXD migrate to other host

By CK. Date: . Last updated: .

Migrate containers to another host

Assuming LXD is running on both hosts. See LXD on Alpine and LXD Init.

Preparation

Port needs to be opened on both hosts.

Both hosts:

sudo ufw allow 8443 comment 'lxc migration'
# maybe only allow single IP, e.g.
# sudo ufw allow from 111.111.111.111 to 222.222.222.222 port 8443 proto tcp comment 'lxc migration'

New host (green):

lxc config set core.https_address 222.222.222.222:8443
lxc config set core.trust_password somepassword

Old host (red):

lxc remote add green 222.222.222.222 # use password from above
lxc config set core.https_address 111.111.111.111:8443

Migration

Now either create a snapshot and transfer that (live migration), or shut the container down and copy it.

Either:

lxc snapshot container1
lxc info container1 # snapshot should be listed
lxc copy container1/snap0 green:container1 --verbose

or:

lxc stop container1
lxc copy container1 green:container1 --verbose

Cleanup

Shut down the http server.

both

lxc config unset core.https_address

Remove firewall rules

sudo ufw status numbered
sudo ufw delete # numbers from above for port 8443

Delete snapshots (if created above)

lxc delete container1/snap0

LXD