File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -287,6 +287,35 @@ func main() {
287287 os .Exit (1 )
288288 }
289289 fmt .Printf ("Image '%s' loaded successfully.\n " , image .Name )
290+ case "image" :
291+ if len (os .Args ) < 3 {
292+ fmt .Println ("Error: Subcommand required for image" )
293+ os .Exit (1 )
294+ }
295+ switch os .Args [2 ] {
296+ case "rm" :
297+ if len (os .Args ) < 4 {
298+ fmt .Println ("Error: Image name required for rm" )
299+ os .Exit (1 )
300+ }
301+ imageName := os .Args [3 ]
302+ imagePath := filepath .Join (imagesDir , imageName )
303+
304+ if _ , err := os .Stat (imagePath ); os .IsNotExist (err ) {
305+ fmt .Printf ("Error: Image '%s' does not exist.\n " , imageName )
306+ os .Exit (1 )
307+ }
308+
309+ if err := os .RemoveAll (imagePath ); err != nil {
310+ fmt .Printf ("Error: Failed to delete image '%s': %v\n " , imageName , err )
311+ os .Exit (1 )
312+ }
313+
314+ fmt .Printf ("Image '%s' deleted successfully.\n " , imageName )
315+ default :
316+ fmt .Println ("Error: Unknown subcommand for image" )
317+ os .Exit (1 )
318+ }
290319 default :
291320 printUsage ()
292321 os .Exit (1 )
@@ -306,6 +335,7 @@ func printUsage() {
306335 fmt .Println (" basic-docker network-attach <network-id> <container-id> Attach a container to a network" )
307336 fmt .Println (" basic-docker network-detach <network-id> <container-id> Detach a container from a network" )
308337 fmt .Println (" basic-docker load <tar-file-path> Load an image from a tar file" )
338+ fmt .Println (" basic-docker image rm <image-name> Remove an image by name" )
309339}
310340
311341func printSystemInfo () {
You can’t perform that action at this time.
0 commit comments