How to delete container with lxc (LXD) command on Linux

Want to delete LXD based container with lxc command on Linux? Try these simple tips. To delete LXD instances/container and snapshots, we use the lxc delete command. However, the container/instance must be stopped, and all snapshots must be removed before removing the Linux container with the lxc command.

Tutorial details
Difficulty level Easy
Root privileges No
Requirements LXD with lxc on Linux
Est. reading time 2 mintues
Let us see syntax and example to delete container with lxc.


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'


You learned how to remove LXD based instance/container using the lxc command on Linux. See help as follows:
lxc help delete

  Delete instances and snapshots

  lxc delete [:][/] [[:][/]...] [flags]

  delete, rm

  -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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • tipton Jan 22, 2021 @ 17:57

    How do I delete an interface defined with lxd after I have removed the container that it bridged to?

    • 🐧 Vivek Gite Jan 30, 2021 @ 11:23

      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.

  • Sidney Salvage Apr 2, 2021 @ 12:46

    Simple yet hard to find info. thank you for the blog.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum