Docker is a project development and software-sharing technology widely used worldwide. It provides many built-in components used to manage its services, such as Docker Compose. Moreover, “docker-compose” is a command line utility for running the multi-container programs or services defined in the docker-compose file.
Occasionally, developers want to restart Docker compose from scratch and clean all its containers and volume.
This blog will demonstrate how to clean up Docker compose.
How to Clean up Docker Compose?
To clean up Docker compose to start it from scratch, follow the listed steps.
Step 1: Start Docker Compose
To create and start a container through Docker compose, utilize the “docker-compose up” command. Here, the “-d” option is used to execute the container in the container:
Step 2: Stop or Remove Docker Compose
To stop and remove the docker container created by “docker-compose”, use the “docker-compose down” command:
Alternatively, the “rm” command is also used to remove the Docker compose container as shown below:
Step 3: Remove All Containers
In order to remove all containers, go through the provided command. Here, the “-f” option is used to remove containers forcefully, “-a” is used to remove all containers, and “-q” is used to display only the relevant containers id:
Step 4: Remove Docker Volume
The Docker volume is the data and backup file that can be required by another container. To remove all Docker volumes, use the provided command:
Step 5: Restart Docker Compose
Now, restart the Docker compose with the help of the provided command. This command will create and start the new container:
That was all about cleaning up the Docker Compose.
Conclusion
To clean up the Docker compose, first stop and remove the Docker container using the “docker-compose down” command. To remove the Docker compose container, utilize the “docker-compose rm” command. Next, remove the Docker volume to clean all data using the “docker volume rm $(docker volume ls -q)” command. Then, again start the Docker compose through the “docker-compose up” command. This write-up has demonstrated how to clean up Docker compose.