This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Nahuel Segovia
Hi! If you don't know that Docker can manage physical resources, this is the place to learn about it and keep your production servers running faster.
In my current job, we have a lot of Docker containers running in production, but the problem was that we never considered how much CPU memory it occupies in our servers.
To solve this, in Docker, using docker-compose, we have a section named "deploy" that lets us manage limits and reservations of RAM. For example, here we have a Web Service based on Python and Django which has a Postgres database.
In this docker-compose.yml you can see "deploy" with "resources", that we need to configure for reserve quantity of RAM that can use the container and set a limit that which it can reach
version: '3.8'
services:
web:
build: .
volumes:
- .:/code
ports:
- "8081:80"
command: "python3 manage.py runserver 0.0.0.0:80"
deploy:
resources:
limits: #Definiendo el lĂmite de acceso a memoria RAM y nĂşcleos CPU
cpus: 0.50
memory: 512M
reservations: #Reservando espacio de memoria RAM y nĂşcelos del CPU
cpus: 0.25
memory: 128M
database:
image: postgres:14.1-alpine
restart: always
environment:
POSTGRES_DB: dockerized
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
PG_SYSTEM_MAX_CONNECTIONS: 500
ports:
- '5432:5432'
volumes:
- database:/var/lib/postgresql/data
volumes:
database:
So, with
docker stats
we can see the information of the containers that are running and confirm that everything as we expected:
This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Nahuel Segovia
Nahuel Segovia | Sciencx (2023-02-18T15:59:31+00:00) How to manage physical resources in your Docker containers and keep production servers fast?. Retrieved from https://www.scien.cx/2023/02/18/how-to-manage-physical-resources-in-your-docker-containers-and-keep-production-servers-fast/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.