Remove all Docker Containers
Stop the container(s):
cd ~/mydocker-repo-folder; docker-compose down;
Delete all containers :
docker rm -f $(docker ps -a -q)
Delete all volumes:
docker volume rm $(docker volume ls -q)
Saving and Restoring Docker Containers
In cases where you cannot for whatever reason build docker containers on your local system, do not fear. Docker allows you to save and import backed up images of containers.
It is a good habit to routinely save containers. Just open a terminal and use the docker save command. Example here:
docker save -o ~/Desktop/my_docker_image.tar laravel
Once that is saved you can share it with other developers or keep it as a personal backup. You can also share it with another developer directly using JustBeamIt.
Restoring from a Container Image
If one of your containers is acting wonky, you can get the name and image id with the following command:
You can see the image name and id in the list.
If the container is running, you can shut it all down with “docker-compose down”. Then you can delete the offending container with the docker rm command. Here is an example:
# kill docker compose
docker image rm 3f8c96702c14
Now you can load a new container to replace the broken one. To do this you will need to get an image from another developer or use one you previously saved.
To load the container from the image use the docker load command. Example here:
docker load -i ~/Desktop/my_docker_image.tar