{"id":165,"date":"2024-07-21T11:56:44","date_gmt":"2024-07-21T11:56:44","guid":{"rendered":"https:\/\/dockerpros.com\/?p=165"},"modified":"2024-07-21T11:56:44","modified_gmt":"2024-07-21T11:56:44","slug":"what-is-a-multi-stage-build-in-docker","status":"publish","type":"post","link":"https:\/\/dockerpros.com\/fr\/introduction-to-docker\/what-is-a-multi-stage-build-in-docker\/","title":{"rendered":"What is a multi-stage build in Docker?"},"content":{"rendered":"<h1>Understanding Multi-Stage Builds in Docker<\/h1>\n<p>Docker has revolutionized the way we think about building, shipping, and running applications. As the demand for lightweight, efficient, and easily deployable applications continues to rise, so does the need for advanced techniques that streamline the development workflow. One such technique is the <span class=\"glossaryai-tooltip glossary-term-740\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\" target=\"_blank\">multi-stage build<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A multi-stage build is a Docker optimization technique that enables the separation of build and runtime environments. By using multiple FROM statements in a single Dockerfile, developers can streamline image size and enhance security by excluding unnecessary build dependencies in the final image.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, which plays an essential role in optimizing Docker images. This article will explain what multi-stage builds are, their benefits, how they work, and best practices for using them effectively.<\/p>\n<h2>What is a Multi-Stage Build?<\/h2>\n<p>A <span class=\"glossaryai-tooltip glossary-term-740\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\" target=\"_blank\">multi-stage build<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A multi-stage build is a Docker optimization technique that enables the separation of build and runtime environments. By using multiple FROM statements in a single Dockerfile, developers can streamline image size and enhance security by excluding unnecessary build dependencies in the final image.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is a feature in Docker that allows you to use multiple <code>FROM<\/code> statements in a single <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>. It enables the creation of optimized images by separating the build environment from the runtime environment. With a <span class=\"glossaryai-tooltip glossary-term-740\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\" target=\"_blank\">multi-stage build<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A multi-stage build is a Docker optimization technique that enables the separation of build and runtime environments. By using multiple FROM statements in a single Dockerfile, developers can streamline image size and enhance security by excluding unnecessary build dependencies in the final image.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, you can compile your application in one stage and then <span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">copy<\/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> only the necessary artifacts to 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> in another stage. This reduces the size of 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> and only includes the files required to <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> the application, helping to keep your containers lightweight and efficient.<\/p>\n<p>This powerful feature was introduced in Docker 17.05 and has since become a popular practice among developers looking to enhance their Docker workflows.<\/p>\n<h2>Why Use Multi-Stage Builds?<\/h2>\n<h3>1. Reduced Image Size<\/h3>\n<p>One of the most significant advantages of multi-stage builds is the reduction in <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> size. Traditional Docker builds often include unnecessary build dependencies and files in 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, which can lead to bloated images. With multi-stage builds, you can ensure that only the files needed for runtime are included in 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This not only saves disk space but also speeds up the deployment process by reducing the time required to pull 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> from a <span class=\"glossaryai-tooltip glossary-term-658\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/registry\/\" target=\"_blank\">registry<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A registry is a centralized database that stores information about various entities, such as software installations, system configurations, or user data. It serves as a crucial component for system management and configuration.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/registry\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h3>2. Simplified Dockerfile<\/h3>\n<p>Multi-stage builds can simplify your <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> by breaking it down into distinct stages. Each stage can have its own set of dependencies and configurations, which allows for better organization and clarity. Developers can easily see what is being built, how it is being built, and what is included in 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<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. Enhanced Security<\/h3>\n<p>By minimizing the number of files and dependencies included in 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, multi-stage builds can enhance security. A smaller attack surface means fewer potential vulnerabilities. Additionally, you can avoid including developer tools, build scripts, and other sensitive information in the production <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h3>4. Improved Build Times<\/h3>\n<p>Multi-stage builds can improve build times by allowing you to cache intermediate layers. Docker caches each layer of 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, so if a layer hasn\u2019t changed, Docker can reuse it in subsequent builds. By organizing your <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> into stages effectively, you can take advantage of this caching mechanism and reduce the time spent on builds.<\/p>\n<h3>5. Flexibility in Build Environments<\/h3>\n<p>Multi-stage builds allow you to use different base images for each stage. For example, you might use a heavier <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> with all development dependencies for building your application and a minimal <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> for the final runtime environment. This flexibility lets you optimize your images based on the specific needs of each stage.<\/p>\n<h2>How Multi-Stage Builds Work<\/h2>\n<p>To understand how multi-stage builds work, let\u2019s break down the process with an example. Consider a simple application written in Go. In a traditional <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 might see something like this:<\/p>\n<pre><code class=\"language-dockerfile\">FROM golang:1.16 AS builder\nWORKDIR \/app\nCOPY . .\nRUN go build -o myapp .\n\nFROM alpine:latest\nWORKDIR \/app\nCOPY --from=builder \/app\/myapp .\nCMD [\".\/myapp\"]<\/code><\/pre>\n<h3>Explanation of the Example<\/h3>\n<ol>\n<li>\n<p><strong>First Stage (Build Stage)<\/strong><\/p>\n<p>In the first stage, we use the official Go <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> (<code>golang:1.16<\/code>) as 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> contains all the necessary tools to compile Go applications. We set the working directory to <code>\/app<\/code>, <span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">copy<\/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> the application code into the <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/container\/\" target=\"_blank\">container<\/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>, and <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> the <code>go build<\/code> command to compile the application. The result is a binary executable named <code>myapp<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Second Stage (Final Stage)<\/strong><\/p>\n<p>In the second stage, we use a much smaller 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, <code>alpine:latest<\/code>, which is minimal and designed for running applications. We set the working directory to <code>\/app<\/code> and use the <code><span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">COPY<\/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<\/code> command to <span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">copy<\/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> only the compiled binary from the first stage into this 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<\/li>\n<li>\n<p><strong>Running the Application<\/strong><\/p>\n<p>Finally, we specify the command to <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> our application using the <code><span class=\"glossaryai-tooltip glossary-term-670\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/cmd\/\" target=\"_blank\">CMD<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">CMD, or Command Prompt, is a command-line interpreter in Windows operating systems. It allows users to execute commands, automate tasks, and manage system files through a text-based interface.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/cmd\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code> directive. The resulting <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is significantly smaller since it only contains the <code>myapp<\/code> binary and the minimal runtime environment.<\/p>\n<\/li>\n<\/ol>\n<h3>Multi-Stage Build with Multiple Stages<\/h3>\n<p>You can also create more complex multi-stage builds that involve several stages. For example, you might want to <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> tests at a certain stage before proceeding to 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. Here\u2019s an example of a multi-stage <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> that includes a testing stage:<\/p>\n<pre><code class=\"language-dockerfile\">FROM golang:1.16 AS builder\nWORKDIR \/app\nCOPY . .\nRUN go build -o myapp .\n\nFROM golang:1.16 AS test\nWORKDIR \/app\nCOPY --from=builder \/app\/myapp .\nRUN go test .\/...\n\nFROM alpine:latest\nWORKDIR \/app\nCOPY --from=builder \/app\/myapp .\nCMD [\".\/myapp\"]<\/code><\/pre>\n<p>In this case, we added a testing stage that uses the Go <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> again. The tests will be <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> against the binary built in the first stage. If the tests pass, the final stage will <span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/copy\/\" target=\"_blank\">copy<\/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> the binary into the Alpine <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h2>Best Practices for Multi-Stage Builds<\/h2>\n<p>To get the most out of multi-stage builds, consider the following best practices:<\/p>\n<h3>1. Use Specific Tags for Base Images<\/h3>\n<p>When specifying base images, use specific tags instead of <code>latest<\/code>. Using specific tags helps ensure that your builds are reproducible and do not break due to unexpected changes in 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h3>2. Keep Stages Focused<\/h3>\n<p>Each stage should have a single responsibility. For example, one stage should be dedicated to building the application, while another should handle testing or packaging. This makes your <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> easier to maintain and understand.<\/p>\n<h3>3. Optimize for Caching<\/h3>\n<p>Take advantage of Docker&#8217;s caching mechanism by ordering your commands strategically. Place commands that change infrequently at the top, allowing Docker to cache those layers and speed up subsequent builds.<\/p>\n<h3>4. Minimize Layers<\/h3>\n<p>While multi-stage builds can help reduce <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> size, be mindful of the number of layers you create. Each command 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> creates a new layer, so consider combining commands where appropriate to minimize the number of layers.<\/p>\n<h3>5. Clean Up Build Artifacts<\/h3>\n<p>If you have any temporary files or build artifacts that are not needed in 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, make sure to clean them up in the final stage. This further reduces the size of 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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> and enhances security.<\/p>\n<h3>6. Leverage Environment Variables<\/h3>\n<p>You can use environment variables to configure your application at runtime. By defining variables in the final stage, you can keep your build stages clean and focused on their specific tasks.<\/p>\n<h2>Conclusion<\/h2>\n<p>Multi-stage builds are a powerful feature in Docker that enables developers to create optimized, efficient, and secure images. By leveraging this technique, you can significantly reduce <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\">An image is a visual representation of an object or scene, typically composed of pixels in digital formats. It can convey information, evoke emotions, and facilitate communication across various media.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> sizes, improve build times, and keep your Dockerfiles organized and manageable. As containerization continues to gain traction, understanding and implementing multi-stage builds will be an essential skill for developers looking to streamline their workflows and enhance their applications.<\/p>\n<p>By following best practices and using multi-stage builds effectively, you can ensure that your Docker images are not only lightweight but also secure and performant, making your applications ready for deployment in today\u2019s fast-paced development environment.<\/p>","protected":false},"excerpt":{"rendered":"<p>A <span class=\"glossaryai-tooltip glossary-term-740\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\" target=\"_blank\">construction multi-\u00e9tapes<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A multi-stage build is a Docker optimization technique that enables the separation of build and runtime environments. By using multiple FROM statements in a single Dockerfile, developers can streamline image size and enhance security by excluding unnecessary build dependencies in the final image.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/fr\/wiki\/multi-stage-build\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> in Docker allows developers to use multiple FROM statements in a single <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>. This technique optimizes <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 by separating the build environment from the final product.<\/p>","protected":false},"author":1,"featured_media":406,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-165","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-introduction-to-docker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What is a multi-stage build in Docker? - 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\/introduction-a-docker\/what-is-a-multi-stage-build-in-docker\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is a multi-stage build in Docker? - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"A multi-stage build in Docker allows developers to use multiple FROM statements in a single Dockerfile. This technique optimizes image size by separating the build environment from the final product.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/fr\/introduction-a-docker\/what-is-a-multi-stage-build-in-docker\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-21T11:56:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.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=\"author\" content=\"dockerpros\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"dockerpros\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/\"},\"author\":{\"name\":\"dockerpros\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4\"},\"headline\":\"What is a multi-stage build in Docker?\",\"datePublished\":\"2024-07-21T11:56:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/\"},\"wordCount\":1111,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dockerpros.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg\",\"articleSection\":[\"Introduction to Docker\"],\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/\",\"url\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/\",\"name\":\"What is a multi-stage build in Docker? - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg\",\"datePublished\":\"2024-07-21T11:56:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg\",\"width\":800,\"height\":600,\"caption\":\"what-is-a-multi-stage-build-in-docker-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dockerpros.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is a multi-stage build in Docker?\"}]},{\"@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\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4\",\"name\":\"dockerpros\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442\",\"caption\":\"dockerpros\"},\"sameAs\":[\"https:\/\/dockerpros.com\/\"],\"url\":\"https:\/\/dockerpros.com\/fr\/author\/dockerpros\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Qu'est-ce qu'un build multi-\u00e9tapes dans Docker ? - 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\/introduction-a-docker\/what-is-a-multi-stage-build-in-docker\/","og_locale":"fr_FR","og_type":"article","og_title":"What is a multi-stage build in Docker? - Dockerpros","og_description":"A multi-stage build in Docker allows developers to use multiple FROM statements in a single Dockerfile. This technique optimizes image size by separating the build environment from the final product.","og_url":"https:\/\/dockerpros.com\/fr\/introduction-a-docker\/what-is-a-multi-stage-build-in-docker\/","og_site_name":"Dockerpros","article_published_time":"2024-07-21T11:56:44+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg","type":"image\/jpeg"}],"author":"dockerpros","twitter_card":"summary_large_image","twitter_misc":{"\u00c9crit par":"dockerpros","Dur\u00e9e de lecture estim\u00e9e":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#article","isPartOf":{"@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/"},"author":{"name":"dockerpros","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4"},"headline":"What is a multi-stage build in Docker?","datePublished":"2024-07-21T11:56:44+00:00","mainEntityOfPage":{"@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/"},"wordCount":1111,"commentCount":0,"publisher":{"@id":"https:\/\/dockerpros.com\/#organization"},"image":{"@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg","articleSection":["Introduction to Docker"],"inLanguage":"fr-FR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/","url":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/","name":"Qu'est-ce qu'un build multi-\u00e9tapes dans Docker ? - Dockerpros","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg","datePublished":"2024-07-21T11:56:44+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/what-is-a-multi-stage-build-in-docker_165.jpg","width":800,"height":600,"caption":"what-is-a-multi-stage-build-in-docker-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/es\/introduccion-a-docker\/un-multi-stage-build-en-docker-es-una-caracteristica-que-permite-crear-imagenes-de-docker-mas-eficientes-y-optimizadas-mediante-el-uso-de-multiples-etapas-de-construccion-cada-etapa-puede-utilizar-un\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dockerpros.com\/"},{"@type":"ListItem","position":2,"name":"What is a multi-stage build in Docker?"}]},{"@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\/"}},{"@type":"Person","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4","name":"professionnels Docker","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/image\/","url":"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442","contentUrl":"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442","caption":"dockerpros"},"sameAs":["https:\/\/dockerpros.com\/"],"url":"https:\/\/dockerpros.com\/fr\/author\/dockerpros\/"}]}},"_links":{"self":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/posts\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/comments?post=165"}],"version-history":[{"count":0,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/posts\/165\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/media\/406"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/categories?post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dockerpros.com\/fr\/wp-json\/wp\/v2\/tags?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}