Unable to remove a container using machinectl

861 views Asked by At

I pulled a nixos container and now want to remove it.

I enter:

sudo machinectl remove nixos-21-tar

But the return message is:

Could not remove image: Access denied

If I list the images I get:

$ machinectl list-images
  NAME         TYPE      RO USAGE CREATED MODIFIED
  debian       directory no   n/a n/a     n/a     
  nixos-21-tar directory no   n/a n/a     n/a

EDIT:

I think the image has been corrupted and the owner/group is wrong:

sudo tree /var/lib/machines/nixos-21-tar/
/var/lib/machines/nixos-21-tar/
└── var
    └── empty

sudo ls -alR /var/lib/machines/nixos-21-tar/
/var/lib/machines/nixos-21-tar:
total 12
drwxrwxrwx 3 699334656 699334656 4096 Apr 18 18:38 .
drwxrwxrwx 4 root      root      4096 Apr 21 17:23 ..
drwxrwxrwx 3 699334656 699334656 4096 Apr 18 18:38 var

/var/lib/machines/nixos-21-tar/var: 
total 12
drwxrwxrwx 3 699334656 699334656 4096 Apr 18 18:38 .
drwxrwxrwx 3 699334656 699334656 4096 Apr 18 18:38 ..
dr-xr-xr-x 2 root      root      4096 Mar 11 17:29 empty

/var/lib/machines/nixos-21-tar/var/empty:
total 8
dr-xr-xr-x 2 root      root      4096 Mar 11 17:29 .
drwxrwxrwx 3 699334656 699334656 4096 Apr 18 18:38 ..
1

There are 1 answers

1
C.C. Hsu On

In my Fedora 38 environment with SELinux enabled, I also get the same message.

I temporarily disable SELinux then I can successfully remove the container.

[user@fedora-workstation ~]$ machinectl remove f38
Could not remove image: Access denied
[user@fedora-workstation ~]$ sudo machinectl remove f38
Could not remove image: Access denied
[user@fedora-workstation ~]$ sudo setenforce 0
[user@fedora-workstation ~]$ sudo machinectl remove f38
[user@fedora-workstation ~]$ sudo setenforce 1
[user@fedora-workstation ~]$