How to limit CPU and memory usage of containers in Docker Compose?

Original link: https://blog.xiaoz.org/archives/18729

Recently, in the process of using open source statistics Umami, I found that the CPU and memory are often full, causing other services to be unable to use normally. Umami I use docker-compose for deployment, so I plan to use docker-compose to limit the CPU and memory usage of the container to solve this problem. Tucao, so I searched for relevant documents to find a way to limit the resource usage of the container. It gave me the feeling that

This article is transferred from: https://blog.xiaoz.org/archives/18729
This site is only for collection, and the copyright belongs to the original author.