问题
I've looked all over, but can't see if there is a way. I have a couple LXC containers running Ubuntu 14.04 on top of a Ubuntu 14.04 Host. They've become pretty important to me, so I want to be able to easily backup / migrate the LXC containers to another server if the host's hardware should fail.
I've built a new Ubuntu 15.1 server now with LXD and have logged out and back in and see the new group. For testing, I tar'd one of my existing LXC containers up with the --numeric-owner
switch on my 14.04 Host:
tar --numeric-owner -czvf ContToBeMoved.tgz /var/lib/lxc/my_container
---then on new server ---
tar --numeric-owner -xzvf ContToBeMoved.tgz -C /var/lib/lxc/
...and have successfully restored the LXC container on the new server 15.1 server.
When I run the LXD commands though, LXD doesn't see the container. I tried moving the container to the /var/lib/lxd/containers
directory and still, LXD doesn't see it. Is there a way to edit / clone / migrate the LXC container so that we can use LXD moving forward?
Thanks in advance.
回答1:
LXD uses a sqlite database for container configuration so just dumping the container's rootfs in place won't be quite enough.
The easiest way to do what you want is to create a new container with LXD, then remove its rootfs from /var/lib/lxd/containers/NAME/rootfs and substitute the one from your original host.
Note that LXD runs unprivileged containers by default, if your source container was privileged (/var/lib/lxc/NAME/rootfs is owned by root:root instead of 100000:100000), then you'll want to run the following too:
lxc config set NAME security.privileged true
来源:https://stackoverflow.com/questions/33377916/migrating-lxc-to-lxd