Junior — Middle
What to do if, when trying to run a Docker container, it is found that the host does not have enough resources to accommodate it?
sobes.tech AI
Answer from AI
If there are insufficient resources on the host when launching a Docker container (such as memory, CPU time, or disk space), the following steps can be taken:
- Check current resource usage with commands like
top,htop,free -m,df -h. - Free up resources: stop or remove unnecessary containers, clean up unused images and volumes (
docker system prune). - Configure resource limits for containers to prevent excessive consumption.
- If resources are constantly insufficient, consider scaling the infrastructure: add more memory, CPU, or use clustering (e.g., Docker Swarm or Kubernetes).
Example of cleaning up unused resources:
# Remove all stopped containers, unused images, and volumes
docker system prune -a --volumes