如何在新主机上移动并运行 Linux 容器?

如何在新主机上移动并运行 Linux 容器?

将 Linux 容器移动到新主机的正确步骤是什么?这是我所做的但没有成功的事情:

  1. 压缩包含linux容器的目录: sudo tar -cjf sample_container.tar.bz2 <path-to-container>/sample_container
  2. 将压缩的 tar 文件复制到新主机(通过 scp、rsync 等)
  3. 在新主机上,解压缩 tar 文件: sudo -jxvf sample_container.tar.bz2
  4. sample_container/config使用新路径更新rootfs(即新主机上的路径)

按照上述步骤似乎不起作用。我究竟做错了什么?

更新: 这是我尝试运行容器时得到的日志输出:

lxc-start 20161111164704.185 ERROR    lxc_conf - conf.c:mount_rootfs:807 - Permission denied - failed to get real path for '/home/newhost/dir1/dir2/lxc/mycontainer_trusty_lxc/rootfs'
lxc-start 20161111164704.185 ERROR    lxc_conf - conf.c:setup_rootfs:1221 - failed to mount rootfs
lxc-start 20161111164704.185 ERROR    lxc_conf - conf.c:do_rootfs_setup:3631 - failed to setup rootfs for 'mycontainer_trusty_lxc'
lxc-start 20161111164704.185 ERROR    lxc_conf - conf.c:lxc_setup:3713 - Error setting up rootfs mount after spawn
lxc-start 20161111164704.185 ERROR    lxc_start - start.c:do_start:834 - failed to setup the container
lxc-start 20161111164704.185 ERROR    lxc_sync - sync.c:__sync_wait:57 - An error occurred in another process (expected sequence number 3)
lxc-start 20161111164704.185 ERROR    lxc_start - start.c:__lxc_start:1354 - failed to spawn 'mycontainer_trusty_lxc'
lxc-start 20161111164709.723 ERROR    lxc_start_ui - tools/lxc_start.c:main:344 - The container failed to start.
lxc-start 20161111164709.723 ERROR    lxc_start_ui - tools/lxc_start.c:main:346 - To get more details, run the container in foreground mode.
lxc-start 20161111164709.723 ERROR    lxc_start_ui - tools/lxc_start.c:main:348 - Additional information can be obtained by setting the --logfile and --logpriority options.

相关内容