{"id":1339,"date":"2024-07-23T12:36:03","date_gmt":"2024-07-23T12:36:03","guid":{"rendered":"https:\/\/dockerpros.com\/?post_type=glossary&#038;p=1339"},"modified":"2024-07-23T12:36:03","modified_gmt":"2024-07-23T12:36:03","slug":"dockerfile-cpu-shares","status":"publish","type":"glossary","link":"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile-cpu-shares\/","title":{"rendered":"Dockerfile \u2013cpu-shares"},"content":{"rendered":"<h1>Compr\u00e9hension <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\" target=\"_blank\">Dockerfile<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A Dockerfile is a script containing a series of instructions to automate the creation of Docker images. It specifies the base image, application dependencies, and configuration, facilitating consistent deployment across environments.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> <code>--cpu-shares<\/code>Une analyse approfondie de l'allocation des ressources<\/h1>\n<p>Docker is an essential tool for modern software development, particularly when it comes to containerization. Among other things, it allows developers to create, deploy, and manage applications seamlessly in isolated environments. One of the critical aspects of Docker is resource management, which enables you to allocate and control system resources effectively among various containers. One of the parameters used to influence CPU allocation is <code>--cpu-shares<\/code>. This article will provide an in-depth analysis of <code>--cpu-shares<\/code> in Docker, covering its importance, usage, practical implications, and best practices for effective resource management.<\/p>\n<h2>Qu'est-ce que <code>parts de CPU<\/code>?<\/h2>\n<p>The <code>--cpu-shares<\/code> L'option dans Docker est utilis\u00e9e pour d\u00e9finir le poids relatif du temps CPU allou\u00e9 \u00e0 un <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. The value specified does not represent an absolute CPU limit; rather, it indicates a prioritization factor against other containers running on the same host. By default, Docker assigns a value of 1024 to all containers unless specified otherwise. A <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> with a higher <code>--cpu-shares<\/code> value will receive more CPU time compared to a <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> with a lower value when the system is under load.<\/p>\n<p>Par exemple, si vous avez deux conteneurs : un avec 1024 <code>parts de CPU<\/code> and another with 512, the first <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> will receive double the CPU time of the second when CPU resources are constrained.<\/p>\n<h2>Importance de l'allocation des ressources dans Docker<\/h2>\n<p>Effective resource allocation is crucial for maintaining the performance and stability of applications running in containers. Mismanagement can lead to performance degradation, slow response times, or even <span class=\"glossaryai-tooltip glossary-term-681\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/service\/\" target=\"_blank\">service<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Le service fait r\u00e9f\u00e9rence \u00e0 l'acte de fournir une assistance ou un soutien pour r\u00e9pondre \u00e0 des besoins ou des exigences sp\u00e9cifiques. Dans divers domaines, il englobe le service client, le support technique et les services professionnels, en mettant l'accent sur l'efficacit\u00e9 et la satisfaction de l'utilisateur.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/service\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> outages. Understanding how to use <code>--cpu-shares<\/code> peut am\u00e9liorer de mani\u00e8re significative les performances globales et la fiabilit\u00e9 de vos applications containeris\u00e9es.<\/p>\n<h3>Avantages de l'utilisation <code>--cpu-shares<\/code><\/h3>\n<ol>\n<li>\n<p><strong>Contr\u00f4le Fin<\/strong>En fixant <code>parts de CPU<\/code>, vous pouvez affiner les conteneurs qui b\u00e9n\u00e9ficient d'un acc\u00e8s prioritaire aux ressources CPU. Cela est particuli\u00e8rement b\u00e9n\u00e9fique dans les environnements multi-locataires, o\u00f9 plusieurs applications ou services <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\" target=\"_blank\">run<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">\"RUN\" refers to a command in various programming languages and operating systems to execute a specified program or script. It initiates processes, providing a controlled environment for task execution.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> en parall\u00e8le et entrer en concurrence pour les ressources du processeur.<\/p>\n<\/li>\n<li>\n<p><strong>Gestion dynamique des ressources<\/strong>: <code>--cpu-shares<\/code> permet une allocation dynamique des ressources en fonction de la charge actuelle et des besoins des applications. Vous pouvez ajuster les parts selon les exigences changeantes de vos charges de travail, en veillant \u00e0 ce que les applications critiques re\u00e7oivent les ressources n\u00e9cessaires lorsqu'elles en ont le plus besoin.<\/p>\n<\/li>\n<li>\n<p><strong>Simplifi\u00e9 <span class=\"glossaryai-tooltip glossary-term-696\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/scaling\/\" target=\"_blank\">Scaling<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Scaling refers to the process of adjusting the capacity of a system to accommodate varying loads. It can be achieved through vertical scaling, which enhances existing resources, or horizontal scaling, which adds additional resources.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/scaling\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/strong>: When deploying applications across multiple containers, having control over CPU shares simplifies <span class=\"glossaryai-tooltip glossary-term-696\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/scaling\/\" target=\"_blank\">scaling<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Scaling refers to the process of adjusting the capacity of a system to accommodate varying loads. It can be achieved through vertical scaling, which enhances existing resources, or horizontal scaling, which adds additional resources.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/scaling\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> operations. You can easily prioritize essential services without manually managing each container&#8217;s CPU allocation.<\/p>\n<\/li>\n<li>\n<p><strong>Performance am\u00e9lior\u00e9e<\/strong>: By appropriately managing CPU resources, you can optimize application performance, especially for resource-intensive workloads. This leads to better user experiences and potentially higher <span class=\"glossaryai-tooltip glossary-term-681\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/service\/\" target=\"_blank\">service<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Le service fait r\u00e9f\u00e9rence \u00e0 l'acte de fournir une assistance ou un soutien pour r\u00e9pondre \u00e0 des besoins ou des exigences sp\u00e9cifiques. Dans divers domaines, il englobe le service client, le support technique et les services professionnels, en mettant l'accent sur l'efficacit\u00e9 et la satisfaction de l'utilisateur.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/service\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> availability.<\/p>\n<\/li>\n<\/ol>\n<h3>How <code>--cpu-shares<\/code> Works<\/h3>\n<p>The underlying mechanism of <code>--cpu-shares<\/code> is based on the Linux kernel&#8217;s Completely Fair Scheduler (CFS). The CFS equally divides CPU time among running processes based on their assigned shares. Therefore, the proportion of CPU time a <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> receives is determined by its <code>parts de CPU<\/code> relative to all other containers on the same host.<\/p>\n<p>When containers are running without any CPU constraints, the scheduler ensures that each <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> gets a fair slice of CPU time based on its share value. If a <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is allowed to use more CPU resources than it is currently using, it can consume more as needed, ensuring that it does not starve under load.<\/p>\n<h3>Cadre <code>--cpu-shares<\/code> dans un Dockerfile<\/h3>\n<p>Pour r\u00e9gler <code>parts de CPU<\/code> dans un <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\" target=\"_blank\">Dockerfile<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A Dockerfile is a script containing a series of instructions to automate the creation of Docker images. It specifies the base image, application dependencies, and configuration, facilitating consistent deployment across environments.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, you would typically use the <code>docker <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\" target=\"_blank\">run<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">\"RUN\" refers to a command in various programming languages and operating systems to execute a specified program or script. It initiates processes, providing a controlled environment for task execution.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code> commande avec le <code>--cpu-shares<\/code> option. Voici un exemple :<\/p>\n<pre><code class=\"language-bash\">docker <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\" target=\"_blank\">run<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">\"RUN\" refers to a command in various programming languages and operating systems to execute a specified program or script. It initiates processes, providing a controlled environment for task execution.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> --cpu-shares=2048 my-container<\/code><\/pre>\n<p>In this example, the <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> nomm\u00e9 <code>my-container<\/code> is allocated double the CPU share compared to the default setting. However, you cannot set <code>parts de CPU<\/code> directly within the <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\" target=\"_blank\">Dockerfile<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A Dockerfile is a script containing a series of instructions to automate the creation of Docker images. It specifies the base image, application dependencies, and configuration, facilitating consistent deployment across environments.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> using a specific directive. Instead, you must configure it at runtime.<\/p>\n<h3>Cas d'usage pratiques<\/h3>\n<h4>Scenario 1: Web Server vs. Batch Processing<\/h4>\n<p>Imagine a scenario where you are running a web server and a batch processing application on the same host. The web server requires quick response times to handle incoming user requests, while the batch processing application can tolerate longer execution times. In this case, you might want to allocate higher <code>parts de CPU<\/code> to the web server and lower <code>parts de CPU<\/code> to the batch processing application:<\/p>\n<pre><code class=\"language-bash\"># Start the web server <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> with higher CPU shares\ndocker <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\" target=\"_blank\">run<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">\"RUN\" refers to a command in various programming languages and operating systems to execute a specified program or script. It initiates processes, providing a controlled environment for task execution.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> --cpu-shares=2048 web-server\n\n# Start the batch processing <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> with lower CPU shares\ndocker <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\" target=\"_blank\">run<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">\"RUN\" refers to a command in various programming languages and operating systems to execute a specified program or script. It initiates processes, providing a controlled environment for task execution.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> --cpu-shares=512 batch-processor<\/code><\/pre>\n<p>Dans cette configuration, le serveur web aura une priorit\u00e9 plus \u00e9lev\u00e9e en ce qui concerne l'allocation du processeur, garantissant ainsi que les demandes des utilisateurs sont trait\u00e9es rapidement.<\/p>\n<h4>Scenario 2: Load Testing and Performance Tuning<\/h4>\n<p>During load testing, you might want to simulate different loads on your application. By adjusting <code>parts de CPU<\/code>, you can monitor how your application behaves under varying levels of CPU contention. You can <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\" target=\"_blank\">run<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">\"RUN\" refers to a command in various programming languages and operating systems to execute a specified program or script. It initiates processes, providing a controlled environment for task execution.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> multiple instances of your application, tweaking their CPU shares accordingly, and evaluate performance and responsiveness.<\/p>\n<h3>Monitoring CPU Usage<\/h3>\n<p>To effectively manage <code>parts de CPU<\/code>, Il est essentiel de surveiller l'utilisation du processeur et les m\u00e9triques de performance. Docker fournit plusieurs outils et commandes pour cela.<\/p>\n<ul>\n<li>\n<p><strong>Statistiques Docker<\/strong>Vous pouvez utiliser le <code>docker stats<\/code> commande pour obtenir des m\u00e9triques en temps r\u00e9el sur l'utilisation des ressources pour tous les conteneurs en cours d'ex\u00e9cution.<\/p>\n<pre><code class=\"language-bash\">docker stats<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>Outils de surveillance des performances<\/strong>: Tools like Grafana, Prometheus, or cAdvisor can be integrated to visualize <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> metrics over time, allowing for more advanced analysis and tuning.<\/p>\n<\/li>\n<\/ul>\n<h3>Meilleures pratiques pour l'utilisation <code>--cpu-shares<\/code><\/h3>\n<ol>\n<li>\n<p><strong>Comprendre vos charges de travail<\/strong>: Avant de r\u00e9gler <code>parts de CPU<\/code>, il est imp\u00e9ratif d'analyser la nature de vos charges de travail : certaines peuvent n\u00e9cessiter une priorit\u00e9 plus \u00e9lev\u00e9e tandis que d'autres peuvent \u00eatre rel\u00e9gu\u00e9es \u00e0 des parts inf\u00e9rieures.<\/p>\n<\/li>\n<li>\n<p><strong>Commencez avec les valeurs par d\u00e9faut<\/strong>: Il est souvent pr\u00e9f\u00e9rable de commencer par le d\u00e9faut <code>parts de CPU<\/code> valeur de 1024, puis ajuster en fonction des indicateurs de performance observ\u00e9s et des exigences op\u00e9rationnelles.<\/p>\n<\/li>\n<li>\n<p><strong>Test and Iterate<\/strong>La gestion des ressources n'est pas une configuration ponctuelle. Surveillez continuellement les performances de l'application et ajustez <code>parts de CPU<\/code> selon les besoins, en se basant sur l'utilisation et les donn\u00e9es de performance r\u00e9elles.<\/p>\n<\/li>\n<li>\n<p><strong>Avoid Over-provisioning<\/strong>: While it may be tempting to allocate high <code>parts de CPU<\/code> to ensure optimal performance, be cautious of over-provisioning, as it could lead to resource contention, affecting the overall system stability.<\/p>\n<\/li>\n<li>\n<p><strong>Utilisation en conjonction avec d'autres limites<\/strong>Pour un contr\u00f4le plus granulaire de l'allocation des ressources, envisagez d'utiliser <code>--processeurs<\/code> \u00e0 c\u00f4t\u00e9 de <code>--cpu-shares<\/code>. Le <code>--processeurs<\/code> setting allows you to limit the number of CPU cores available to a <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, providing a more comprehensive resource management strategy.<\/p>\n<\/li>\n<\/ol>\n<h3>Conclusion<\/h3>\n<p>The <code>--cpu-shares<\/code> option in Docker is a powerful feature for managing CPU allocation among containers. By understanding how it works and applying best practices, developers can optimize their containerized applications for better performance, resource utilization, and stability. In an era where applications are increasingly deployed in cloud environments and multi-tenant architectures, effective resource management is not just an advantage but a necessity.<\/p>\n<p>As you delve deeper into <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">conteneur<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> <span class=\"glossaryai-tooltip glossary-term-657\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/orchestration\/\" target=\"_blank\">orchestration<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">L'orchestration d\u00e9signe la gestion et la coordination automatis\u00e9es de syst\u00e8mes et de services complexes. Elle optimise les processus en int\u00e9grant diverses composantes, en garantissant un fonctionnement efficace et une utilisation optimale des ressources.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/orchestration\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> et de gestion, la connaissance de param\u00e8tres tels que <code>--cpu-shares<\/code> will serve as a crucial element in the toolkit of any developer or system administrator. By taking a proactive approach to managing resources, you can ensure that your applications <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\" target=\"_blank\">run<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">\"RUN\" refers to a command in various programming languages and operating systems to execute a specified program or script. It initiates processes, providing a controlled environment for task execution.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> smoothly and efficiently, even under varying loads, ultimately leading to a better user experience and more reliable <span class=\"glossaryai-tooltip glossary-term-681\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/service\/\" target=\"_blank\">service<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Le service fait r\u00e9f\u00e9rence \u00e0 l'acte de fournir une assistance ou un soutien pour r\u00e9pondre \u00e0 des besoins ou des exigences sp\u00e9cifiques. Dans divers domaines, il englobe le service client, le support technique et les services professionnels, en mettant l'accent sur l'efficacit\u00e9 et la satisfaction de l'utilisateur.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/service\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> delivery.<\/p>","protected":false},"excerpt":{"rendered":"<p>The `\u2013cpu-shares` option in a <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\" target=\"_blank\">Dockerfile<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A Dockerfile is a script containing a series of instructions to automate the creation of Docker images. It specifies the base image, application dependencies, and configuration, facilitating consistent deployment across environments.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> permet aux utilisateurs de sp\u00e9cifier des parts de CPU relatives pour les conteneurs. Ce param\u00e8tre influence l'allocation du CPU en cas de contention, offrant ainsi un moyen de g\u00e9rer efficacement les ressources.<\/p>","protected":false},"author":1,"featured_media":1991,"parent":0,"template":"","glossary-cat":[],"class_list":["post-1339","glossary","type-glossary","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Dockerfile -cpu-shares - Dockerpros<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile-cpu-shares\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dockerfile -cpu-shares - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"The `--cpu-shares` option in a Dockerfile allows users to specify relative CPU shares for containers. This setting influences CPU allocation during contention, providing a way to manage resources effectively.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile-cpu-shares\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/\",\"url\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/\",\"name\":\"Dockerfile -cpu-shares - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg\",\"datePublished\":\"2024-07-23T12:36:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg\",\"width\":800,\"height\":600,\"caption\":\"dockerfile-cpu-shares-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dockerpros.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Glossary\",\"item\":\"https:\/\/dockerpros.com\/fr\/wiki\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Dockerfile &#8211;cpu-shares\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dockerpros.com\/#website\",\"url\":\"https:\/\/dockerpros.com\/\",\"name\":\"Dockerpros\",\"description\":\"DockerPros \u2013 Your Ultimate Docker Resource Hub\",\"publisher\":{\"@id\":\"https:\/\/dockerpros.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dockerpros.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dockerpros.com\/#organization\",\"name\":\"Dockerpros\",\"url\":\"https:\/\/dockerpros.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/Dockerpros_logo_blanco.png\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/Dockerpros_logo_blanco.png\",\"width\":532,\"height\":114,\"caption\":\"Dockerpros\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dockerfile -cpu-shares - Dockerpros","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile-cpu-shares\/","og_locale":"fr_FR","og_type":"article","og_title":"Dockerfile -cpu-shares - Dockerpros","og_description":"The `--cpu-shares` option in a Dockerfile allows users to specify relative CPU shares for containers. This setting influences CPU allocation during contention, providing a way to manage resources effectively.","og_url":"https:\/\/dockerpros.com\/fr\/wiki\/dockerfile-cpu-shares\/","og_site_name":"Dockerpros","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/","url":"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/","name":"Dockerfile -cpu-shares - Dockerpros","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg","datePublished":"2024-07-23T12:36:03+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cpu-shares_1339.jpg","width":800,"height":600,"caption":"dockerfile-cpu-shares-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cpu-shares\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dockerpros.com\/"},{"@type":"ListItem","position":2,"name":"Glossary","item":"https:\/\/dockerpros.com\/fr\/wiki\/"},{"@type":"ListItem","position":3,"name":"Dockerfile &#8211;cpu-shares"}]},{"@type":"WebSite","@id":"https:\/\/dockerpros.com\/#website","url":"https:\/\/dockerpros.com\/","name":"Dockerpros","description":"DockerPros \u2013 Votre centre de ressources Docker incontournable","publisher":{"@id":"https:\/\/dockerpros.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dockerpros.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/dockerpros.com\/#organization","name":"Dockerpros","url":"https:\/\/dockerpros.com\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/dockerpros.com\/#\/schema\/logo\/image\/","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/Dockerpros_logo_blanco.png","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/Dockerpros_logo_blanco.png","width":532,"height":114,"caption":"Dockerpros"},"image":{"@id":"https:\/\/dockerpros.com\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/glossary\/1339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/glossary"}],"about":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/types\/glossary"}],"author":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":0,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/glossary\/1339\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/media\/1991"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/media?parent=1339"}],"wp:term":[{"taxonomy":"glossary-cat","embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/glossary-cat?post=1339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}