Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | LXD with lxc on Linux |
Time | 2m |
Syntax
The syntax is simple:
lxc delete instance
lxc delete instance/snapshot
lxc delete instance {options}
## rm is alias for delete ##
lxc rm container/snapshot
Listing all containers / instances
Open the terminal application and then type the following command:
lxc list
lxc ls
## list container name, state and snapshots ##
lxc list -c nsS
List of all my LXD instances:
+--------------------+---------+-----------+
| NAME | STATE | SNAPSHOTS |
+--------------------+---------+-----------+
| alpine | RUNNING | 0 |
+--------------------+---------+-----------+
| arch | STOPPED | 1 |
+--------------------+---------+-----------+
| c1 | STOPPED | 0 |
+--------------------+---------+-----------+
| centos-6 | STOPPED | 0 |
+--------------------+---------+-----------+
| centos-7 | STOPPED | 0 |
+--------------------+---------+-----------+
| centos-8 | RUNNING | 0 |
+--------------------+---------+-----------+
| debdocker | RUNNING | 0 |
+--------------------+---------+-----------+
....
.....
..
| opensusenginx-test | STOPPED | 0 |
+--------------------+---------+-----------+
| oracle-7 | STOPPED | 0 |
+--------------------+---------+-----------+
| plamo | STOPPED | 0 |
+--------------------+---------+-----------+
| sabayon | STOPPED | 0 |
+--------------------+---------+-----------+
| ubuntu-20-4 | STOPPED | 0 |
+--------------------+---------+-----------+
| ubuntunginx-test | STOPPED | 0 |
+--------------------+---------+-----------+
WARNING: The following commands will delete the LXD instance/container including all snapshots. Always back up all critical data, including LXD containers, as this action is irreversible. See how to backup and restore LXD instance for more info.
Deleting container with lxc command on Linux for LXD
Let us remove lxd instance named arch, run:
lxc delete arch
Verify it:
lxc list
You will get an error on screen as follows when the instance is running on Linux and you type ‘lxc delete’ command:
Error: The instance is currently running, stop it first or pass –force
To get rid of this problem either stop the Linux container or pass the --force option:
lxc stop {container1} && lxc delete {container1}
## OR ##
lxc delete {container1} --force
Removing container snapshot with lxc command
We can create a snapshot of “alpine” called “snap0” as follows:
lxc snapshot alpine snap0
Display info about the instance, enter:
lxc info alpine
Delete a snapshot of “alpine” called “snap0”, run:
lxc delete alpine/snap0
## verify it with the help of egrep command ##
lxc list -c nsS | egrep 'NAME|STATE|alpine'
Conclusion
You learned how to remove LXD based instance/container using the lxc command on Linux. See help as follows:
lxc help delete
Description: Delete instances and snapshots Usage: lxc delete [:][/] [[:][/]...] [flags] Aliases: delete, rm Flags: -f, --force Force the removal of running instances -i, --interactive Require user confirmation Global Flags: --debug Show all debug messages --force-local Force using the local unix socket -h, --help Print help --project string Override the source project -q, --quiet Don't show progress information -v, --verbose Show all information messages --version Print version number
- Install LXD container hypervisor on Ubuntu 16.04 LTS
- How to install and setup LXC (Linux Container) on Fedora Linux 26
- Set up LXD container under KVM or Xen virtual machine
- List VM images in LXD (Linux Containers)
- Upgrade LXD containers powered by Ubuntu/Debian or CentOS Linux
- Auto start LXD containers at boot time in Linux
- Command to rename LXD / LXC container
- Run commands on Linux Container (LXD) instance at provision launch time
- Use LXD (Linux containers) in a shell script to create VM when the cloud instance launches
- Move/migrate LXD VM to another host on Linux
- Fedora install and set up LXD
- CentOS 7.x install and set up LXD server
- Install LXD pure-container hypervisor on Ubuntu 18.04 LTS
- Create snapshots with lxc command for LXD
- Set up and install LXD on CentOS/RHEL 8
- Ubuntu 20.04 LTS install and set up LXD
- Full backup and restore LXD containers
- Disable firewall and NAT rules on the LXD bridge
- Delete or remove LXD container using the lxc
🐧 2 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
How do I delete an interface defined with lxd after I have removed the container that it bridged to?
You still need a bridge as long as you have LXD installed for other containers. If you remove the LXD package, the bridge will get deleted too.