{"id":1244,"date":"2024-07-23T12:16:07","date_gmt":"2024-07-23T12:16:07","guid":{"rendered":"https:\/\/dockerpros.com\/?post_type=glossary&#038;p=1244"},"modified":"2024-07-23T12:21:35","modified_gmt":"2024-07-23T12:21:35","slug":"docker-build-cache","status":"publish","type":"glossary","link":"https:\/\/dockerpros.com\/fr\/wiki\/docker-build-cache\/","title":{"rendered":"Cache de construction Docker"},"content":{"rendered":"<h1>Understanding Docker Build Cache: An Advanced Guide<\/h1>\n<p>Le Docker Build Cache est un m\u00e9canisme qui am\u00e9liore l'efficacit\u00e9 de la construction d'images Docker. <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> Le processus de construction en tirant parti de la mise en cache des couches interm\u00e9diaires d'images, qui peuvent \u00eatre r\u00e9utilis\u00e9es lors des constructions ult\u00e9rieures. Cela permet aux d\u00e9veloppeurs d'\u00e9viter les t\u00e2ches redondantes, acc\u00e9l\u00e9rant consid\u00e9rablement le processus de construction lorsque des modifications sont apport\u00e9es. En utilisant intelligemment la mise en cache, Docker aide \u00e0 optimiser l'utilisation des ressources et la gestion du temps, ce qui en fait une fonctionnalit\u00e9 essentielle pour les d\u00e9veloppeurs travaillant avec des applications conteneuris\u00e9es.<\/p>\n<h2>The Architecture of Docker Build Cache<\/h2>\n<p>To grasp the nuances of Docker Build Cache, it&#8217;s important to first understand how Docker images are constructed. A Docker <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> consists of a series of layers, each representing a change made to the filesystem. These layers are created as a result of the commands specified in 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>. The layers are built in a specific order, and Docker maintains a cache of these layers to optimize future builds.<\/p>\n<h3>Dockerfile and Layer Creation<\/h3>\n<p>When 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> is processed, each instruction (like <code><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>, <code><span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">COPIE<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">COPY is a command in computer programming and data management that facilitates the duplication of files or data from one location to another, ensuring data integrity and accessibility.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code>, <code><span class=\"glossaryai-tooltip glossary-term-674\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/add\/\" target=\"_blank\">ADD<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">La commande ADD dans Docker est une instruction utilis\u00e9e dans les Dockerfiles pour copier des fichiers et des r\u00e9pertoires depuis une machine h\u00f4te vers une image Docker pendant le processus de construction. Elle facilite non seulement le transfert de fichiers locaux, mais offre \u00e9galement des fonctionnalit\u00e9s suppl\u00e9mentaires, telles que l'extraction automatique de fichiers compress\u00e9s et le t\u00e9l\u00e9chargement de fichiers distants via HTTP ou HTTPS.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/add\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code>, etc.) g\u00e9n\u00e8re une nouvelle couche. Les couches sont immuables, ce qui signifie qu'une fois cr\u00e9\u00e9es, elles ne peuvent \u00eatre modifi\u00e9es. Chaque couche est identifi\u00e9e par un hachage unique bas\u00e9 sur son contenu. Si le contenu d'une couche reste inchang\u00e9, Docker peut r\u00e9utiliser la version en cache de cette couche pour les constructions suivantes.<\/p>\n<h3>Comportement du cache<\/h3>\n<p>Le m\u00e9canisme de cache de Docker utilise un algorithme sp\u00e9cifique pour d\u00e9terminer s'il faut utiliser une couche mise en cache ou en construire une nouvelle. Ce m\u00e9canisme de cache suit le principe de \"l'invalidation du cache\". Si une partie de la commande d'une couche change, cette couche et toutes les couches suivantes sont reconstruites. Ce comportement permet \u00e0 Docker d'\u00eatre \u00e0 la fois efficace et pr\u00e9visible.<\/p>\n<h2>Types of Build Cache<\/h2>\n<p>Docker supports different types of build caches that developers can utilize to enhance their build processes:<\/p>\n<h3>Cache de build local<\/h3>\n<p>Le cache de construction local est stock\u00e9 sur la machine du d\u00e9veloppeur. Il comprend toutes les couches cr\u00e9\u00e9es lors de la construction des images sur cette machine. Ce cache est cr\u00e9\u00e9 automatiquement au fur et \u00e0 mesure que les couches sont construites et peut \u00eatre r\u00e9utilis\u00e9 lors de constructions futures. Cependant, il est sp\u00e9cifique \u00e0 l'environnement local, ce qui signifie que si un d\u00e9veloppeur change de machine ou d'environnement, il n'aura pas acc\u00e8s \u00e0 ce cache.<\/p>\n<h3>2. Remote Build Cache<\/h3>\n<p>With the introduction of BuildKit, Docker supports remote caching capabilities. This allows developers to push their build cache to remote repositories. Remote caching can significantly speed up builds in Continuous Integration\/Continuous Deployment (CI\/CD) pipelines by allowing multiple developers or CI\/CD agents to share cache layers.<\/p>\n<h3>3. Exportation\/Importation de cache<\/h3>\n<p>Docker also provides the ability to export and import build cache. Using the <code>--cache-depuis<\/code> option, developers can specify existing images or cache stored in a remote <span class=\"glossaryai-tooltip glossary-term-659\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/repository\/\" target=\"_blank\">repository<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A repository is a centralized location where data, code, or documents are stored, managed, and maintained. It facilitates version control, collaboration, and efficient resource sharing among users.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/repository\/\">More \u00bb<\/a><\/span><\/span><span class=\"gai-tooltip-video-wrapper\"><span class=\"gai-tooltip-video\" data-src=\"https:\/\/www.youtube.com\/embed\/_OXj8BGxNPY?rel=0&#038;modestbranding=1\"><\/span><\/span><\/span><\/span><\/span> \u00e0 utiliser comme source de cache pour la construction. Cette fonctionnalit\u00e9 permet une plus grande flexibilit\u00e9 dans la gestion des environnements de construction et acc\u00e9l\u00e8re les constructions en tirant parti des caches existants provenant d'autres sources.<\/p>\n<h2>Optimizing the Build Cache Usage<\/h2>\n<p>To effectively utilize Docker Build Cache, developers can adopt several best practices that will help optimize the way caches are used during the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> build process.<\/p>\n<h3>1. Organisez intelligemment les instructions du Dockerfile<\/h3>\n<p>The order of commands 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> can significantly impact cache efficiency. Instructions that are less likely to change should be placed higher in 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>. For instance, installing dependencies should come before adding application code. This way, if only the application code changes, the dependency layer can still be reused from the cache.<\/p>\n<pre><code class=\"language-dockerfile\"># Efficiently ordering <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> instructions\nFROM <span class=\"glossaryai-tooltip glossary-term-684\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/node\/\" target=\"_blank\">n\u0153ud<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Node, or Node.js, is a JavaScript runtime built on Chrome's V8 engine, enabling server-side scripting. It allows developers to build scalable network applications using asynchronous, event-driven architecture.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/node\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>:14\n\n# Install dependencies\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">COPIE<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">COPY is a command in computer programming and data management that facilitates the duplication of files or data from one location to another, ensuring data integrity and accessibility.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> package*.json .\/\n<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> npm install\n\n# <span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">Copier<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">COPY is a command in computer programming and data management that facilitates the duplication of files or data from one location to another, ensuring data integrity and accessibility.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> application code\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">COPIE<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">COPY is a command in computer programming and data management that facilitates the duplication of files or data from one location to another, ensuring data integrity and accessibility.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> . .\n\n# Build the application\n<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> npm <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> construire<\/code><\/pre>\n<p>Dans l'exemple ci-dessus, si seul le code de l'application change, le <code>npm install<\/code> L'\u00e9tape peut \u00eatre mise en cache, ce qui permet un gain de temps.<\/p>\n<h3>2. Utilisez des builds multi-\u00e9tapes<\/h3>\n<p>Multi-stage builds allow developers to create smaller final images by using multiple <code>FROM<\/code> statements 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>. Each stage can utilize cached layers from previous stages, reducing the overall <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> size and build time. <\/p>\n<pre><code class=\"language-dockerfile\"># First stage: build the application\nFROM <span class=\"glossaryai-tooltip glossary-term-684\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/node\/\" target=\"_blank\">n\u0153ud<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Node, or Node.js, is a JavaScript runtime built on Chrome's V8 engine, enabling server-side scripting. It allows developers to build scalable network applications using asynchronous, event-driven architecture.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/node\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>:14 en tant que constructeur\n\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">COPIE<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">COPY is a command in computer programming and data management that facilitates the duplication of files or data from one location to another, ensuring data integrity and accessibility.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> package*.json .\/\n<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> npm install\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">COPIE<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">COPY is a command in computer programming and data management that facilitates the duplication of files or data from one location to another, ensuring data integrity and accessibility.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> . .\n<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> npm <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> build\n\n# Second stage: create the final image\nFROM nginx:alpine\n\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">COPIE<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">COPY is a command in computer programming and data management that facilitates the duplication of files or data from one location to another, ensuring data integrity and accessibility.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> --from=builder \/app\/build \/usr\/share\/nginx\/html<\/code><\/pre>\n<p>With this approach, if the application code changes, only the build stage needs to be rebuilt, while the final <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> can still benefit from the cached layers of the base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h3>3. Utilize BuildKit<\/h3>\n<p>Docker BuildKit introduit des fonctionnalit\u00e9s de mise en cache et d'ex\u00e9cution parall\u00e8le plus avanc\u00e9es. Pour activer BuildKit, d\u00e9finissez la variable d'environnement <code>DOCKER_BUILDKIT=1<\/code>. With BuildKit, developers can take advantage of features like cache import\/export, automatic layer squashing, and build secrets.<\/p>\n<h3>4. \u00c9vitez les couches inutiles<\/h3>\n<p>Each command in 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> creates a new layer. By minimizing the number of commands, you can reduce the total layer count, which can improve cache performance. Grouping commands using <code>&amp;&amp;<\/code> can help achieve this.<\/p>\n<pre><code class=\"language-dockerfile\"># Instead of multiple <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> commands\n<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> apt-get update &amp;&amp; apt-get install -y \n  package1 \n  package2 \n  package3<\/code><\/pre>\n<p>La r\u00e9duction du nombre de couches minimise la quantit\u00e9 de donn\u00e9es qui doivent \u00eatre mises en cache et acc\u00e9l\u00e8re le processus de construction.<\/p>\n<h3>5. Utilisation <code>--no-cache<\/code> Strategically<\/h3>\n<p>Bien que les caches soient utiles, il y a des moments o\u00f9 vous pourriez vouloir forcer une reconstruction. En utilisant le <code>--no-cache<\/code> option when building an <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> ensures that no cached layers are used. This can be helpful for debugging or ensuring that you have the latest versions of dependencies.<\/p>\n<h2>Diagnostic des probl\u00e8mes de cache de construction\n\nBuild cache issues can be tricky to diagnose. This page describes some common issues and how to resolve them.\n\nProbl\u00e8mes de cache de construction peuvent \u00eatre difficiles \u00e0 diagnostiquer. Cette page d\u00e9crit certains probl\u00e8mes courants et comment les r\u00e9soudre.\n\nBuild cache is not being used<\/h2>\n<p>Despite best efforts, issues with the build cache may arise. Diagnosing these issues can be crucial for maintaining efficient build processes.<\/p>\n<h3>1. \u00c9checs de cache de construction<\/h3>\n<p>Un probl\u00e8me courant est de rencontrer des erreurs de cache, o\u00f9 Docker d\u00e9cide de reconstruire des couches que vous vous attendez \u00e0 voir mises en cache. Cela se produit g\u00e9n\u00e9ralement lorsque :<\/p>\n<ul>\n<li>The command has changed.<\/li>\n<li>Le contenu des fichiers copi\u00e9s ou ajout\u00e9s a chang\u00e9.<\/li>\n<li>The base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> has been updated, invalidating its layers.<\/li>\n<\/ul>\n<p>Pour \u00e9tudier les d\u00e9fauts de cache, vous pouvez utiliser le <code>docker build --progress=plain<\/code> flag, which provides detailed output on which layers are being built and which are being cached.<\/p>\n<h3>Gonflement du cache<\/h3>\n<p>Over time, the local build cache may become bloated with unused layers. Regularly cleaning up the cache can help mitigate this issue. Using commands like <code>Nettoyer le syst\u00e8me Docker<\/code> Peut aider \u00e0 supprimer les images, conteneurs et r\u00e9seaux inutilis\u00e9s, y compris les couches mises en cache.<\/p>\n<h3>3. Surveillance des performances de construction<\/h3>\n<p>Des outils comme BuildKit de Docker offrent des informations sur les performances de construction. En analysant les temps de construction et les mod\u00e8les d'utilisation du cache, les d\u00e9veloppeurs peuvent identifier les goulots d'\u00e9tranglement et les domaines \u00e0 am\u00e9liorer.<\/p>\n<h2>Conclusion<\/h2>\n<p>Docker Build Cache is a powerful feature that can significantly enhance the efficiency of building Docker images. Understanding the architecture, types, and best practices for utilizing the build cache can lead to faster builds and more efficient resource usage. By strategically ordering <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> instructions, leveraging multi-stage builds, using BuildKit, and regularly diagnosing cache issues, developers can master the use of Docker Build Cache, ultimately leading to improved development workflows.<\/p>\n<p>As the world of containerization evolves, staying updated with the latest Docker features and enhancements will continue to be vital for developers aiming to optimize their CI\/CD processes. Embracing the intricacies of Docker Build Cache ensures that you\u2019re well-equipped to handle the complexities of modern application development in a containerized environment.<\/p>","protected":false},"excerpt":{"rendered":"<p>Docker Build Cache optimizes the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\" target=\"_blank\">image<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Une image est une repr\u00e9sentation visuelle d'un objet ou d'une sc\u00e8ne, g\u00e9n\u00e9ralement compos\u00e9e de pixels dans les formats num\u00e9riques. Elle peut transmettre des informations, susciter des \u00e9motions et faciliter la communication \u00e0 travers diff\u00e9rents m\u00e9dias.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> Le processus de construction en stockant les couches interm\u00e9diaires. Cela r\u00e9duit le temps de construction et la consommation de ressources, permettant aux d\u00e9veloppeurs de g\u00e9rer efficacement les d\u00e9pendances et de rationaliser les flux de travail.<\/p>","protected":false},"author":1,"featured_media":1805,"parent":0,"template":"","glossary-cat":[],"class_list":["post-1244","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>Docker Build Cache - 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\/docker-build-cache\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Docker Build Cache - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"Docker Build Cache optimizes the image building process by storing intermediate layers. This reduces build time and resource consumption, allowing developers to efficiently manage dependencies and streamline workflows.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/fr\/wiki\/docker-build-cache\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-23T12:21:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.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\/docker-build-cache\/\",\"url\":\"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/\",\"name\":\"Docker Build Cache - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.jpg\",\"datePublished\":\"2024-07-23T12:16:07+00:00\",\"dateModified\":\"2024-07-23T12:21:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.jpg\",\"width\":800,\"height\":600,\"caption\":\"docker-build-cache-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#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\":\"Docker Build Cache\"}]},{\"@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":"Cache Docker Build - Dockerpros\n\nLorsque vous ex\u00e9cutez la commande docker build, chaque instruction du Dockerfile est ex\u00e9cut\u00e9e \u00e9tape par \u00e9tape, et chaque \u00e9tape cr\u00e9e une nouvelle image. Si vous ex\u00e9cutez \u00e0 nouveau la commande docker build, Docker utilisera le cache de construction pour acc\u00e9l\u00e9rer le processus de construction. Le cache de construction est une fonctionnalit\u00e9 qui permet \u00e0 Docker de r\u00e9utiliser les images interm\u00e9diaires cr\u00e9\u00e9es lors de la construction pr\u00e9c\u00e9dente.\n\nLe cache de construction est bas\u00e9 sur le hachage de chaque instruction du Dockerfile. Si l'instruction n'a pas chang\u00e9 depuis la derni\u00e8re construction, Docker utilisera l'image interm\u00e9diaire correspondante du cache. Si l'instruction a chang\u00e9, Docker reconstruira l'image interm\u00e9diaire et mettra \u00e0 jour le cache.\n\nLe cache de construction peut consid\u00e9rablement acc\u00e9l\u00e9rer le processus de construction, en particulier pour les Dockerfile complexes avec de nombreuses instructions. Cependant, il est important de noter que le cache de construction peut \u00e9galement causer des probl\u00e8mes si les instructions du Dockerfile ne sont pas correctement ordonn\u00e9es. Par exemple, si vous copiez des fichiers dans le conteneur avant d'installer les d\u00e9pendances, le cache de construction peut ne pas \u00eatre utilis\u00e9 correctement.\n\nPour \u00e9viter les probl\u00e8mes li\u00e9s au cache de construction, il est recommand\u00e9 de suivre les meilleures pratiques suivantes :\n\n1. Placez les instructions qui changent le moins souvent en haut du Dockerfile.\n2. Utilisez des instructions sp\u00e9cifiques pour copier des fichiers, telles que COPY ou ADD, plut\u00f4t que des instructions g\u00e9n\u00e9riques telles que RUN.\n3. Utilisez des balises de version pour les images de base afin de garantir la coh\u00e9rence des constructions.\n4. \u00c9vitez d'utiliser des instructions qui peuvent modifier le syst\u00e8me de fichiers, telles que RUN apt-get update, car elles peuvent invalider le cache de construction.\n\nEn suivant ces meilleures pratiques, vous pouvez tirer le meilleur parti du cache de construction Docker et acc\u00e9l\u00e9rer le processus de construction de vos images Docker.","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\/docker-build-cache\/","og_locale":"fr_FR","og_type":"article","og_title":"Docker Build Cache - Dockerpros","og_description":"Docker Build Cache optimizes the image building process by storing intermediate layers. This reduces build time and resource consumption, allowing developers to efficiently manage dependencies and streamline workflows.","og_url":"https:\/\/dockerpros.com\/fr\/wiki\/docker-build-cache\/","og_site_name":"Dockerpros","article_modified_time":"2024-07-23T12:21:35+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.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\/docker-build-cache\/","url":"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/","name":"Cache Docker Build - Dockerpros\n\nLorsque vous ex\u00e9cutez la commande docker build, chaque instruction du Dockerfile est ex\u00e9cut\u00e9e \u00e9tape par \u00e9tape, et chaque \u00e9tape cr\u00e9e une nouvelle image. Si vous ex\u00e9cutez \u00e0 nouveau la commande docker build, Docker utilisera le cache de construction pour acc\u00e9l\u00e9rer le processus de construction. Le cache de construction est une fonctionnalit\u00e9 qui permet \u00e0 Docker de r\u00e9utiliser les images interm\u00e9diaires cr\u00e9\u00e9es lors de la construction pr\u00e9c\u00e9dente.\n\nLe cache de construction est bas\u00e9 sur le hachage de chaque instruction du Dockerfile. Si l'instruction n'a pas chang\u00e9 depuis la derni\u00e8re construction, Docker utilisera l'image interm\u00e9diaire correspondante du cache. Si l'instruction a chang\u00e9, Docker reconstruira l'image interm\u00e9diaire et mettra \u00e0 jour le cache.\n\nLe cache de construction peut consid\u00e9rablement acc\u00e9l\u00e9rer le processus de construction, en particulier pour les Dockerfile complexes avec de nombreuses instructions. Cependant, il est important de noter que le cache de construction peut \u00e9galement causer des probl\u00e8mes si les instructions du Dockerfile ne sont pas correctement ordonn\u00e9es. Par exemple, si vous copiez des fichiers dans le conteneur avant d'installer les d\u00e9pendances, le cache de construction peut ne pas \u00eatre utilis\u00e9 correctement.\n\nPour \u00e9viter les probl\u00e8mes li\u00e9s au cache de construction, il est recommand\u00e9 de suivre les meilleures pratiques suivantes :\n\n1. Placez les instructions qui changent le moins souvent en haut du Dockerfile.\n2. Utilisez des instructions sp\u00e9cifiques pour copier des fichiers, telles que COPY ou ADD, plut\u00f4t que des instructions g\u00e9n\u00e9riques telles que RUN.\n3. Utilisez des balises de version pour les images de base afin de garantir la coh\u00e9rence des constructions.\n4. \u00c9vitez d'utiliser des instructions qui peuvent modifier le syst\u00e8me de fichiers, telles que RUN apt-get update, car elles peuvent invalider le cache de construction.\n\nEn suivant ces meilleures pratiques, vous pouvez tirer le meilleur parti du cache de construction Docker et acc\u00e9l\u00e9rer le processus de construction de vos images Docker.","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.jpg","datePublished":"2024-07-23T12:16:07+00:00","dateModified":"2024-07-23T12:21:35+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/wiki\/docker-build-cache\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-build-cache_1244.jpg","width":800,"height":600,"caption":"docker-build-cache-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/wiki\/docker-build-cache\/#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":"Docker Build Cache"}]},{"@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\/1244","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\/1244\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/media\/1805"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/media?parent=1244"}],"wp:term":[{"taxonomy":"glossary-cat","embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/glossary-cat?post=1244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}