How to manage physical resources in your Docker containers and keep production servers fast?

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 tha…


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:

Image description


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Nahuel Segovia


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to manage physical resources in your Docker containers and keep production servers fast?." Nahuel Segovia | Sciencx - Saturday February 18, 2023, https://www.scien.cx/2023/02/18/how-to-manage-physical-resources-in-your-docker-containers-and-keep-production-servers-fast/
HARVARD
Nahuel Segovia | Sciencx Saturday February 18, 2023 » How to manage physical resources in your Docker containers and keep production servers fast?., viewed ,<https://www.scien.cx/2023/02/18/how-to-manage-physical-resources-in-your-docker-containers-and-keep-production-servers-fast/>
VANCOUVER
Nahuel Segovia | Sciencx - » How to manage physical resources in your Docker containers and keep production servers fast?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/02/18/how-to-manage-physical-resources-in-your-docker-containers-and-keep-production-servers-fast/
CHICAGO
" » How to manage physical resources in your Docker containers and keep production servers fast?." Nahuel Segovia | Sciencx - Accessed . https://www.scien.cx/2023/02/18/how-to-manage-physical-resources-in-your-docker-containers-and-keep-production-servers-fast/
IEEE
" » How to manage physical resources in your Docker containers and keep production servers fast?." Nahuel Segovia | Sciencx [Online]. Available: https://www.scien.cx/2023/02/18/how-to-manage-physical-resources-in-your-docker-containers-and-keep-production-servers-fast/. [Accessed: ]
rf:citation
» How to manage physical resources in your Docker containers and keep production servers fast? | Nahuel Segovia | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.