How to rename LXD / LXC container
H
ow do I rename an LXD managed LXC container under a Linux operating system?
You can move or rename containers within or in between lxd instances. In this quick tutorial, I will show how to rename an LXD managed LXC container using lxc command line.
How to rename a local container
Let us say you want to rename a local container named file-server to debian-wheezy. The syntax is:
lxc move {old-lxc-name} {new-lxc-name}
Please note that renaming of running container not allowed. So first stop the container, enter:
$ lxc stop file-server
Now rename it:
$ lxc move file-server debian-wheezy
Start it:
$ lxc start debian-wheezy
Verify it:
$ lxc info debian-wheezy
Sample outputs:
Fig.01: Rename a local container
Login to debian-wheezy LXD container:
$ lxc exec debian-wheezy bash
Change hostname and updated /etc/hosts if you want:
# echo debian-wheezy > /etc/hostname
# sed -i s/file-server/debian-wheezy/g /etc/hosts
# exit
$ lxc restart debian-wheezy
Verify new changes:
$ lxc exec debian-wheezy bash
root@debian-wheezy:~# cat /etc/os-release
Sample outputs:
PRETTY_NAME= Debian GNU/Linux 7 (wheezy)
NAME= Debian GNU/Linux
VERSION_ID= 7
VERSION= 7 (wheezy)
ID=debian
ANSI_COLOR= 1;31
HOME_URL= http://www.debian.org/
SUPPORT_URL= http://www.debian.org/support/
BUG_REPORT_URL= http://bugs.debian.org/
Also you can move a container between two hosts, renaming it if destination name differs. The syntax is:
$ lxc move [<remote>:][<remote>:][<destination container>]
$ lxc stop server1:foo
$ lxc move server1:foo server2:bar