问题描述
我已经看遍了,但看不到有没有办法.我有几个在 Ubuntu 14.04 主机上运行 Ubuntu 14.04 的 LXC 容器.它们对我来说变得非常重要,所以如果主机的硬件出现故障,我希望能够轻松地将 LXC 容器备份/迁移到另一台服务器.
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.
我现在使用 LXD 构建了一个新的 Ubuntu 15.1 服务器,并且已经注销并重新登录并查看新组.为了进行测试,我使用 14.04 主机上的 --numeric-owner
开关对我现有的 LXC 容器之一进行了 tar'd:
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/
...并已成功在新服务器 15.1 服务器上恢复 LXC 容器.
...and have successfully restored the LXC container on the new server 15.1 server.
当我运行 LXD 命令时,LXD 看不到容器.我尝试将容器移动到 /var/lib/lxd/containers
目录,但 LXD 仍然没有看到它.有没有办法编辑/克隆/迁移 LXC 容器,以便我们可以继续使用 LXD?
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?
提前致谢.
推荐答案
LXD 使用 sqlite 数据库进行容器配置,因此仅将容器的 rootfs 转储到位是不够的.
LXD uses a sqlite database for container configuration so just dumping the container's rootfs in place won't be quite enough.
最简单的方法是使用 LXD 创建一个新容器,然后从/var/lib/lxd/containers/NAME/rootfs 中删除其 rootfs 并替换原始主机中的那个.
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.
请注意,LXD 默认运行非特权容器,如果您的源容器具有特权(/var/lib/lxc/NAME/rootfs 由 root:root 拥有,而不是 100000:100000),那么您需要运行以下也是:
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
这篇关于将 lxc 迁移到 lxd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!