try to unmount rootfs also during destroy_container

This commit is contained in:
Disassembler 2019-12-07 16:57:24 +01:00
parent 7794ada45e
commit ca10263696
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
2 changed files with 4 additions and 2 deletions

View File

@ -60,7 +60,7 @@ parser_cleanup.add_argument('container', help='Container name')
parser_cleanup.add_argument('lxc', nargs=argparse.REMAINDER)
parser_extract = subparsers.add_parser('extract', help='Extracts files or directories from containers rootfs (excluding persistent mounts)')
parser_cleanup.set_defaults(action='extract')
parser_extract.set_defaults(action='extract')
parser_extract.add_argument('container', help='Container name')
parser_extract.add_argument('source', help='Source file or directory within the container')
parser_extract.add_argument('destination', help='Destination file or directory on the host')

View File

@ -20,7 +20,7 @@ def prepare_container(container, layers):
layers = layers.split(',')
mount_rootfs(container, layers, rootfs)
def mount_rootfs(container, layers, mountpoint)
def mount_rootfs(container, layers, mountpoint):
if len(layers) == 1:
# We have only single layer, no overlay needed
subprocess.run(['mount', '--bind', layers[0], mountpoint])
@ -74,6 +74,8 @@ def create_container(container, image):
def destroy_container(container):
# Remove container configuration and directories
rootfs = os.path.join(LXC_ROOT, container, 'rootfs')
unmount_rootfs(rootfs)
try:
shutil.rmtree(os.path.join(LXC_ROOT, container))
except FileNotFoundError: