Docker Container Stop and Delete Scripts

スポンサーリンク
スポンサーリンク

At first

Describes a script for stopping and deleting Docker containers.

The script you are using is published as vm-configure on github, so please download it from github or download it from here.

See the link below for the vm-configure folder configuration.

/guest-share/ubuntu-20.04/docker-stop.sh

This is a script to stop the Docker container.

The location of the script file is in the current directory.

SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR"

The docker directory with the docker-compose.yml file is the current directory.

See the link below for docker-compose.yml.

cd "docker"

The container defined in docker-compose.yml in the current directory is stopped.

docker-compose stop

/guest-share/ubuntu-20.04/docker/docker-destroy.sh

This is a script for destroying Docker containers.

The location of the script file is in the current directory.

SCRIPT_DIR=$(dirname "$0")
cd "$SCRIPT_DIR"

The container defined in docker-compose.yml in the current directory is stopped.

docker-compose stop

 Delete stopped containers, volumes that are not in use, networks that are not in use, and images that are not in use.

docker system prune

Delete an image that is not in use.

echo "y" | docker image prune

Delete volumes that are not in use.

echo "y" | docker volume prune

Delete a network that is not in use.

echo "y" | docker network prune

Get a list of images in docker images and delete them.

echo "y" | docker rmi `docker images -q`

Get a list of volumes in docker volume and delete the volume.

echo "y" | docker volume rm `docker volume ls -q`

Get a list of networks in docker network and delete the network.

echo "y" | docker network rm `docker network ls -q

Deleting the directory where the persisted volumes are stored.

rm -r ../../docker-volumes

Comment

スポンサーリンク