+++ The docker command provides several options for managing Docker containers and images. One of these options is the system prune
command, which can be used to remove unused data from the Docker system. This command can be used to "nuke" everything Docker, by removing all unused containers, images, networks, and volumes. Later you can safely remove docker from the system.
To nuke everything Docker, you can use the following script:
# Stop and remove all running containers
# Remove all unused images
# Remove all unused networks
# Remove all unused volumes
This code uses stops and removes all running containers, removes all unused images, removes all unused networks, and removes all unused volumes. The -f
option is used with the network prune
and volume prune
commands to force the removal of the unused data.
Note that using the system prune
command or the script above will remove all unused data from the Docker system. This can free up a significant amount of disk space, but it can also remove data that you may want to keep. Therefore, it is recommended to use this command with caution and only when you are sure that you want to remove all unused data from the Docker system.
Now to remove docker from Ubuntu, you can use the following commands:
;
;
;
All of these can be written in a simple nice bash script for automation.
#!/bin/bash
## Stop and remove all containers
if [; then
;
;
fi;
## Remove all images
if [; then
;
fi;
## Remove all volumes
if [; then
;
fi;
## Remove all networks
# Skip default networks : bridge, host, none
if [; then
;
fi;
## Remove docker engine and clean
if [; then
;
;
;
fi;