Fedora 25: How to list Linux Containers that aren't stored in the default location?

I've been trying to use and learn more about Linux Containers lately, and I store them here:
/var/lib/lxc/<distro>/<container>

So my arch based containers would be at /var/lib/lxc/arch/arch_sandbox as an example. However, whenever I put a linux container in a location that is not default, lxc-ls does not list the container at all.

Is there a way to have it acknowledge containers in sub directories or elsewhere? It's man page doesn't mention a path designation argument.

The ls command parameter will list the specified directory. You'll have to do a search for rootfs or something and mark the dirs where they turn out to be, then -ls will list the containers in the directory you point to with the --dir parameter, just like you would normally start the containers in the default path without the --dir parameter, but those that aren't in the std path, require the --dir parameter to be found.

1 Like

-P or --lxcpath=PATH will tell the command to use a different path.

Example:

lxc-ls -P /var/lib/lxc/arch

You could try this:

lxc-ls -P /var/lib/lxc/*/

Or if that doesnt work, you could automate it with a script if your directories are all in the same place (or if you know where they all are).

#!/bin/bash

for direc in $(ls -d /var/lib/lxc/*/)
do
    ls-lxc -P $direc
done
1 Like