I work on many projects and tend to spin up tons of containers, containers are lightweight and don't impact my hardware performance, but still, the clutter annoys me.
Usually in your docker-compose.yml file, you would instruct docker-compose to always restart the services. Especially in dev where you could break something. It would be such a pain to constantly have to type "docker start" as you debug, thus the "restart: always" flag just makes life a lot easier.
Since docker-compose always requires a ".yml" file, you either need to pass in the file path via "-f" or you need to be in the same directory as the yaml file when running docker-compose.
As you can imagine, if you started up 5 different projects, now you have to CD 5 times!
One easy alternative is just to run:
docker stop $(docker ps -q)
The cleaner approach would be to run "docker compose down", however, this is super convenient on a busy day when you don't have time to fiddle.
Some other helpful docker commands
Delete unused containers and images to help reduce the amount of disk space docker is using:
docker system prune
Flush all docker logs:
sudo truncate -s 0 /var/lib/docker/containers/*/*.log
View resource usage by containers:
docker stats
View running processes inside a container:
docker top contaner-name
View recent changes on an image:
docker history image-name
Top comments (0)