{"id":1333,"date":"2024-07-23T12:21:35","date_gmt":"2024-07-23T12:21:35","guid":{"rendered":"https:\/\/dockerpros.com\/?post_type=glossary&#038;p=1333"},"modified":"2024-07-23T12:23:47","modified_gmt":"2024-07-23T12:23:47","slug":"dockerfile-cache-von","status":"publish","type":"glossary","link":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-cache-from\/","title":{"rendered":"Dockerfile \u2013cache-from\n\nIn diesem Artikel werden wir uns mit dem Befehl \"Dockerfile \u2013cache-from\" befassen. Dieser Befehl ist ein n\u00fctzliches Werkzeug f\u00fcr Entwickler, die Docker-Images erstellen und optimieren m\u00f6chten. Lassen Sie uns einen genaueren Blick darauf werfen.\n\nDer \"Dockerfile \u2013cache-from\" Befehl erm\u00f6glicht es Ihnen, den Build-Prozess eines Docker-Images zu beschleunigen, indem er die Verwendung von Cache-Schichten erm\u00f6glicht. Wenn Sie ein Docker-Image erstellen, werden verschiedene Schichten erstellt, die die verschiedenen Schritte des Build-Prozesses darstellen. Jede Schicht enth\u00e4lt die \u00c4nderungen, die in diesem Schritt vorgenommen wurden.\n\nNormalerweise erstellt Docker beim Erstellen eines Images jede Schicht von Grund auf neu, auch wenn sich die vorherigen Schichten nicht ge\u00e4ndert haben. Dies kann zu l\u00e4ngeren Build-Zeiten f\u00fchren, insbesondere wenn Sie h\u00e4ufig \u00c4nderungen an Ihrem Dockerfile vornehmen.\n\nMit dem \"Dockerfile \u2013cache-from\" Befehl k\u00f6nnen Sie jedoch angeben, dass Docker eine bereits vorhandene Schicht als Cache verwenden soll. Dies bedeutet, dass Docker die bereits erstellten Schichten wiederverwenden kann, anstatt sie erneut zu erstellen. Dadurch wird der Build-Prozess erheblich beschleunigt.\n\nUm den \"Dockerfile \u2013cache-from\" Befehl zu verwenden, m\u00fcssen Sie zuerst ein Docker-Image erstellen und es in einer Registry speichern. Anschlie\u00dfend k\u00f6nnen Sie beim Erstellen eines neuen Images den Befehl mit dem Namen des bereits vorhandenen Images angeben. Docker wird dann versuchen, die Schichten dieses Images als Cache zu verwenden.\n\nEs ist wichtig zu beachten, dass der \"Dockerfile \u2013cache-from\" Befehl nur funktioniert, wenn die Schichten des bereits vorhandenen Images mit den Schichten des neuen Images kompatibel sind. Wenn sich die Anweisungen im Dockerfile ge\u00e4ndert haben oder neue Anweisungen hinzugef\u00fcgt wurden, kann der Cache m\u00f6glicherweise nicht verwendet werden.\n\nZusammenfassend l\u00e4sst sich sagen, dass der \"Dockerfile \u2013cache-from\" Befehl eine n\u00fctzliche Funktion ist, um den Build-Prozess von Docker-Images zu optimieren. Durch die Verwendung von Cache-Schichten k\u00f6nnen Entwickler Zeit sparen und die Effizienz ihrer Builds verbessern. Es ist jedoch wichtig, sicherzustellen, dass die Schichten des bereits vorhandenen Images mit den Schichten des neuen Images kompatibel sind, um den Cache effektiv nutzen zu k\u00f6nnen."},"content":{"rendered":"<h1>Understanding <code>--cache-from<\/code> in Dockerfile: An Advanced Guide<\/h1>\n<p>Docker is a powerful tool for containerization, allowing developers to package applications with all their dependencies into standardized units, known as containers. One of the key features of Docker that enhances build efficiency is the <code>--cache-from<\/code> option, which leverages previously built images to speed up the build process. In this article, we will delve into the intricacies of <code>--cache-from<\/code>, exploring its use cases, the benefits it provides, its limitations, and best practices for effectively integrating it into your Docker workflow.<\/p>\n<h2>What is <code>--cache-from<\/code>?<\/h2>\n<p>The <code>--cache-from<\/code> flag is used with the <code>docker build<\/code> command to specify an <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> to be used as a cache source for building a Docker <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. When you use <code>--cache-from<\/code>, Docker will check the specified <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> for cached layers before attempting to build new layers. This can significantly reduce build times, especially when working with large images or when the same base images are reused across different builds. By utilizing cached layers, <code>--cache-from<\/code> helps in optimizing the build process, leading to faster iterations and reduced resource consumption.<\/p>\n<h2>The Docker Build Process<\/h2>\n<p>To fully appreciate the advantages of <code>--cache-from<\/code>, it&#8217;s essential to understand how Docker handles the build process. When you <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> a <code>docker build<\/code> command, Docker constructs a new <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> layer by layer, based on the directives specified in the <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<ol>\n<li>\n<p><strong>Layering<\/strong>: Each command in the <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> generates a new layer in the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. For example, <code><span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/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\/de\/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\/de\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code>, and <code><span class=\"glossaryai-tooltip glossary-term-674\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\">The ADD instruction in Docker is a command used in Dockerfiles to copy files and directories from a host machine into a Docker image during the build process. It not only facilitates the transfer of local files but also provides additional functionality, such as automatically extracting compressed files and fetching remote files via HTTP or HTTPS.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/add\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code> commands create layers that can be cached and reused in subsequent builds.<\/p>\n<\/li>\n<li>\n<p><strong>Caching Mechanism<\/strong>: Docker uses a cache to store these layers. When you rebuild an <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, Docker checks the cache to see if it can reuse an existing layer that matches the current build context. If it finds a match, it avoids re-executing the command, thus speeding up the build process.<\/p>\n<\/li>\n<li>\n<p><strong>Layer Identification<\/strong>: Layers are identified by a combination of the command, the context (files and directories in the build context), and their associated metadata (such as environment variables). If any of these components change, Docker will invalidate the cache for that layer and rebuild it.<\/p>\n<\/li>\n<\/ol>\n<h2>Use Cases for <code>--cache-from<\/code><\/h2>\n<h3>1. Multi-Stage Builds<\/h3>\n<p>Multi-stage builds are a powerful feature in Docker that allows developers 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\/de\/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\/de\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This can be particularly useful for optimizing <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> size and separating build environments from final runtime environments. <code>--cache-from<\/code> can be used in multi-stage builds to pull cached layers from previous builds.<\/p>\n<p>For example, you might have a multi-stage <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> that builds an application in one stage and then copies the output to a lighter <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> in the final stage. By using <code>--cache-from<\/code> with the intermediate <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, you can speed up the build process significantly.<\/p>\n<pre><code class=\"language-Dockerfile\"># Dockerfile\nFROM 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<p>You can build this <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> while leveraging a cached version of the <code>builder<\/code> stage:<\/p>\n<pre><code class=\"language-bash\">docker build --cache-from myapp:builder -t myapp:latest .<\/code><\/pre>\n<h3>2. CI\/CD Pipelines<\/h3>\n<p>In Continuous Integration and Continuous Deployment (CI\/CD) environments, build times can become a bottleneck. Using <code>--cache-from<\/code> can help to alleviate this issue by allowing the build process to take advantage of previously built layers.<\/p>\n<p>By caching images in a remote <span class=\"glossaryai-tooltip glossary-term-658\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/registry\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, CI\/CD tools can pull these images as cache sources, reducing the time it takes to build new images. For instance, if your CI\/CD pipeline regularly builds Docker images, you can tag the built images with a specific version and use those tags in subsequent builds.<\/p>\n<pre><code class=\"language-bash\">docker build --cache-from myregistry\/myapp:latest -t myapp:latest .<\/code><\/pre>\n<h3>3. Frequent Development Iterations<\/h3>\n<p>During active development, developers often rebuild images several times a day. In such cases, using <code>--cache-from<\/code> can drastically reduce build times by using a previously built <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> as a cache source. This is particularly useful when the base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> or application dependencies have not changed significantly.<\/p>\n<p>For example, if you are working on a microservice that relies on a shared base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, you can use that base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> as a cache source:<\/p>\n<pre><code class=\"language-bash\">docker build --cache-from myregistry\/mybaseimage:latest -t myservice:latest .<\/code><\/pre>\n<h2>Benefits of Using <code>--cache-from<\/code><\/h2>\n<h3>1. Reduced Build Times<\/h3>\n<p>The primary advantage of using <code>--cache-from<\/code> is the significant reduction in build times. By reusing cached layers from previous builds, Docker can skip execution of commands that have not changed, leading to faster builds.<\/p>\n<h3>2. Efficient Resource Utilization<\/h3>\n<p>By tapping into cached layers, <code>--cache-from<\/code> minimizes the resources required for the build process. This is particularly important in environments with limited resources or where multiple builds are being executed concurrently.<\/p>\n<h3>3. Improved Development Workflow<\/h3>\n<p>For developers, reduced build times translate to quicker feedback loops, allowing for more efficient iterations during the development process. This can enhance overall productivity and improve the quality of the software being developed.<\/p>\n<h3>4. Consistency Across Builds<\/h3>\n<p>Using <code>--cache-from<\/code> can help ensure consistency across builds, especially in CI\/CD environments. By utilizing a common cache source, teams can achieve reproducible builds, making it easier to diagnose issues and maintain application stability.<\/p>\n<h2>Limitations of <code>--cache-from<\/code><\/h2>\n<p>While <code>--cache-from<\/code> provides several advantages, it also has limitations that developers should be aware of:<\/p>\n<h3>1. Cache Invalidation<\/h3>\n<p>Docker&#8217;s caching mechanism relies on a combination of commands, file changes, and metadata. Any change in these aspects can lead to cache invalidation, resulting in a layer being rebuilt even if it was previously cached. This could lead to longer build times if not managed properly.<\/p>\n<h3>2. Cache Size Limitations<\/h3>\n<p>When using <code>--cache-from<\/code>, the size of the cache can impact performance. If the cached <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is too large, it may take longer to pull the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> from a remote <span class=\"glossaryai-tooltip glossary-term-658\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/registry\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, negating some of the benefits of caching. Keeping images lean and manageable can help mitigate this issue.<\/p>\n<h3>3. Network Dependency<\/h3>\n<p>Using remote images as cache sources introduces a dependency on <span class=\"glossaryai-tooltip glossary-term-661\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/network\/\" target=\"_blank\">network<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A network, in computing, refers to a collection of interconnected devices that communicate and share resources. It enables data exchange, facilitates collaboration, and enhances operational efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/network\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> availability. If the cache <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is not available due to <span class=\"glossaryai-tooltip glossary-term-661\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/network\/\" target=\"_blank\">network<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A network, in computing, refers to a collection of interconnected devices that communicate and share resources. It enables data exchange, facilitates collaboration, and enhances operational efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/network\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> issues or if it has been removed from the <span class=\"glossaryai-tooltip glossary-term-658\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/registry\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, the build process may fail or take longer than expected.<\/p>\n<h2>Best Practices for Using <code>--cache-from<\/code><\/h2>\n<p>To make the most out of <code>--cache-from<\/code>, consider the following best practices:<\/p>\n<h3>1. Tagging and Versioning Images<\/h3>\n<p>Use meaningful tags and version numbers for your images in the <span class=\"glossaryai-tooltip glossary-term-658\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/registry\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This practice not only helps in identifying cached layers but also ensures that the correct versions are being used in your build process.<\/p>\n<h3>2. Regularly Clean Up Unused Images<\/h3>\n<p>Regularly clean up unused images and layers from your Docker host and your <span class=\"glossaryai-tooltip glossary-term-658\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/registry\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This helps to maintain a clean environment and ensures that you&#8217;re not using stale or outdated cache layers in your builds.<\/p>\n<h3>3. Monitor Build Performance<\/h3>\n<p>Keep an eye on build performance and cache usage. Tools like Docker&#8217;s buildkit can provide insights into layer caching and help identify bottlenecks in your build process. This information can guide you in optimizing your Dockerfiles for better cache utilization.<\/p>\n<h3>4. Leverage Multi-Stage Builds<\/h3>\n<p>Whenever possible, utilize multi-stage builds to keep your final images small and focused. This not only improves build performance when using <code>--cache-from<\/code> but also enhances security by reducing the attack surface of your images.<\/p>\n<h3>5. Use BuildKit<\/h3>\n<p>Docker BuildKit is an advanced build subsystem that improves build performance and efficiency. Enabling BuildKit can provide better caching capabilities and support for the <code>--cache-from<\/code> option. To enable BuildKit, you can set the environment variable <code>DOCKER_BUILDKIT=1<\/code> before your build command.<\/p>\n<h2>Conclusion<\/h2>\n<p>The <code>--cache-from<\/code> feature in Docker is an invaluable tool for optimizing <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> builds, especially in development and CI\/CD environments. By effectively leveraging cached layers from previously built images, developers can significantly reduce build times, improve resource utilization, and enhance overall workflow efficiency. However, it&#8217;s essential to be aware of the limitations and to follow best practices to ensure effective use of <code>--cache-from<\/code>.<\/p>\n<p>As containerization continues to gain traction, understanding and utilizing advanced features like <code>--cache-from<\/code> will be crucial for developers aiming to streamline their workflows and enhance productivity. By incorporating this feature into your Docker build strategy, you can forge a more efficient and robust development process that keeps pace with the rapid evolution of software development.<\/p>","protected":false},"excerpt":{"rendered":"<p>Die `\u2013cache-from`-Option in <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/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\">Eine Dockerfile ist ein Skript, das eine Reihe von Anweisungen zur Automatisierung der Erstellung von Docker-Images enth\u00e4lt. Sie gibt das Basis-Image, die Anwendungsabh\u00e4ngigkeiten und die Konfiguration an und erm\u00f6glicht so eine konsistente Bereitstellung \u00fcber verschiedene Umgebungen hinweg.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> Der Aufbau erm\u00f6glicht es den Benutzern, zwischengespeicherte Ebenen aus vorhandenen Images zu nutzen. Dies kann den Build-Prozess erheblich beschleunigen, indem zuvor erstellte Ebenen wiederverwendet werden, Redundanz reduziert und die Effizienz verbessert wird.<\/p>","protected":false},"author":1,"featured_media":1979,"parent":0,"template":"","glossary-cat":[],"class_list":["post-1333","glossary","type-glossary","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Dockerfile -cache-from - 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\/de\/wiki\/dockerfile-cache-von\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dockerfile -cache-from - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"The `--cache-from` option in Dockerfile builds allows users to leverage cached layers from existing images. This can significantly speed up the build process by reusing previously built layers, reducing redundancy and improving efficiency.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-cache-von\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-23T12:23:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.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=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data1\" content=\"7\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/\",\"url\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/\",\"name\":\"Dockerfile -cache-from - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.jpg\",\"datePublished\":\"2024-07-23T12:21:35+00:00\",\"dateModified\":\"2024-07-23T12:23:47+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.jpg\",\"width\":800,\"height\":600,\"caption\":\"dockerfile-cache-from-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dockerpros.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Glossary\",\"item\":\"https:\/\/dockerpros.com\/fr\/wiki\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Dockerfile &#8211;cache-from\"}]},{\"@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\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dockerpros.com\/#organization\",\"name\":\"Dockerpros\",\"url\":\"https:\/\/dockerpros.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/Dockerpros_logo_blanco.png\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/Dockerpros_logo_blanco.png\",\"width\":532,\"height\":114,\"caption\":\"Dockerpros\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dockerfile -cache-from - Dockerpros\n\nIn diesem Artikel werden wir uns mit dem Konzept des Docker-Cache und der Verwendung der Option `--cache-from` in Dockerfiles befassen. Der Docker-Cache ist ein leistungsstarkes Werkzeug, das die Erstellung von Docker-Images beschleunigt, indem es bereits erstellte Schichten wiederverwendet. Dies kann die Build-Zeiten erheblich reduzieren, insbesondere bei gro\u00dfen und komplexen Anwendungen.\n\nWas ist der Docker-Cache?\n\nDer Docker-Cache ist ein Mechanismus, der es Docker erm\u00f6glicht, bereits erstellte Schichten von Images zu speichern und bei nachfolgenden Builds wiederzuverwenden. Wenn Sie ein Dockerfile erstellen und einen Build durchf\u00fchren, erstellt Docker f\u00fcr jeden Befehl im Dockerfile eine neue Schicht. Diese Schichten werden in einem Cache gespeichert und k\u00f6nnen bei zuk\u00fcnftigen Builds wiederverwendet werden, wenn sich die Anweisungen nicht ge\u00e4ndert haben.\n\nDie Verwendung des Docker-Cache kann die Build-Zeiten erheblich reduzieren, da Docker nicht jedes Mal von vorne beginnen muss. Stattdessen kann es auf bereits erstellte Schichten zur\u00fcckgreifen und nur die Schichten neu erstellen, die sich ge\u00e4ndert haben.\n\nDie Option `--cache-from`\n\nDie Option `--cache-from` erm\u00f6glicht es Ihnen, einen externen Cache f\u00fcr den Build zu verwenden. Dies ist besonders n\u00fctzlich, wenn Sie ein neues Image auf der Grundlage eines bestehenden Images erstellen m\u00f6chten. Anstatt den gesamten Build-Prozess von vorne zu beginnen, k\u00f6nnen Sie das bestehende Image als Cache verwenden und nur die Schichten neu erstellen, die sich ge\u00e4ndert haben.\n\nDie Syntax f\u00fcr die Verwendung der Option `--cache-from` lautet wie folgt:\n\n```\ndocker build --cache-from  -t  .\n```\n\nHier ist `` der Name des Images, das als Cache verwendet werden soll, und `` ist der Name des neuen Images, das erstellt wird.\n\nBeispiel\n\nAngenommen, Sie haben ein bestehendes Image namens `my-app:v1` und m\u00f6chten ein neues Image namens `my-app:v2` erstellen. Sie k\u00f6nnen die Option `--cache-from` verwenden, um das bestehende Image als Cache zu verwenden:\n\n```\ndocker build --cache-from my-app:v1 -t my-app:v2 .\n```\n\nDocker wird dann das bestehende Image `my-app:v1` als Cache verwenden und nur die Schichten neu erstellen, die sich ge\u00e4ndert haben. Dies kann die Build-Zeiten erheblich reduzieren, insbesondere wenn das bestehende Image bereits viele Schichten enth\u00e4lt.\n\nVorteile der Verwendung von `--cache-from`\n\nDie Verwendung der Option `--cache-from` bietet mehrere Vorteile:\n\n1. Schnellere Build-Zeiten: Durch die Verwendung eines externen Caches k\u00f6nnen Sie die Build-Zeiten erheblich reduzieren, da Docker nicht jedes Mal von vorne beginnen muss.\n\n2. Effiziente Nutzung von Ressourcen: Durch die Wiederverwendung bereits erstellter Schichten k\u00f6nnen Sie Ressourcen wie Zeit und Speicherplatz sparen.\n\n3. Konsistente Builds: Durch die Verwendung eines externen Caches k\u00f6nnen Sie sicherstellen, dass Ihre Builds konsistent sind, da sie auf demselben Basis-Image aufbauen.\n\n4. Einfache Aktualisierung von Images: Wenn Sie ein neues Image auf der Grundlage eines bestehenden Images erstellen m\u00f6chten, k\u00f6nnen Sie die Option `--cache-from` verwenden, um den Build-Prozess zu beschleunigen.\n\nFazit\n\nDie Option `--cache-from` ist ein leistungsstarkes Werkzeug, das die Erstellung von Docker-Images beschleunigt, indem es bereits erstellte Schichten wiederverwendet. Durch die Verwendung eines externen Caches k\u00f6nnen Sie die Build-Zeiten erheblich reduzieren und Ressourcen effizient nutzen. Wenn Sie regelm\u00e4\u00dfig Docker-Images erstellen, sollten Sie die Option `--cache-from` in Betracht ziehen, um Ihre Build-Prozesse zu optimieren.","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\/de\/wiki\/dockerfile-cache-von\/","og_locale":"de_DE","og_type":"article","og_title":"Dockerfile -cache-from - Dockerpros","og_description":"The `--cache-from` option in Dockerfile builds allows users to leverage cached layers from existing images. This can significantly speed up the build process by reusing previously built layers, reducing redundancy and improving efficiency.","og_url":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-cache-von\/","og_site_name":"Dockerpros","article_modified_time":"2024-07-23T12:23:47+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Gesch\u00e4tzte Lesezeit":"7\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/","url":"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/","name":"Dockerfile -cache-from - Dockerpros\n\nIn diesem Artikel werden wir uns mit dem Konzept des Docker-Cache und der Verwendung der Option `--cache-from` in Dockerfiles befassen. Der Docker-Cache ist ein leistungsstarkes Werkzeug, das die Erstellung von Docker-Images beschleunigt, indem es bereits erstellte Schichten wiederverwendet. Dies kann die Build-Zeiten erheblich reduzieren, insbesondere bei gro\u00dfen und komplexen Anwendungen.\n\nWas ist der Docker-Cache?\n\nDer Docker-Cache ist ein Mechanismus, der es Docker erm\u00f6glicht, bereits erstellte Schichten von Images zu speichern und bei nachfolgenden Builds wiederzuverwenden. Wenn Sie ein Dockerfile erstellen und einen Build durchf\u00fchren, erstellt Docker f\u00fcr jeden Befehl im Dockerfile eine neue Schicht. Diese Schichten werden in einem Cache gespeichert und k\u00f6nnen bei zuk\u00fcnftigen Builds wiederverwendet werden, wenn sich die Anweisungen nicht ge\u00e4ndert haben.\n\nDie Verwendung des Docker-Cache kann die Build-Zeiten erheblich reduzieren, da Docker nicht jedes Mal von vorne beginnen muss. Stattdessen kann es auf bereits erstellte Schichten zur\u00fcckgreifen und nur die Schichten neu erstellen, die sich ge\u00e4ndert haben.\n\nDie Option `--cache-from`\n\nDie Option `--cache-from` erm\u00f6glicht es Ihnen, einen externen Cache f\u00fcr den Build zu verwenden. Dies ist besonders n\u00fctzlich, wenn Sie ein neues Image auf der Grundlage eines bestehenden Images erstellen m\u00f6chten. Anstatt den gesamten Build-Prozess von vorne zu beginnen, k\u00f6nnen Sie das bestehende Image als Cache verwenden und nur die Schichten neu erstellen, die sich ge\u00e4ndert haben.\n\nDie Syntax f\u00fcr die Verwendung der Option `--cache-from` lautet wie folgt:\n\n```\ndocker build --cache-from  -t  .\n```\n\nHier ist `` der Name des Images, das als Cache verwendet werden soll, und `` ist der Name des neuen Images, das erstellt wird.\n\nBeispiel\n\nAngenommen, Sie haben ein bestehendes Image namens `my-app:v1` und m\u00f6chten ein neues Image namens `my-app:v2` erstellen. Sie k\u00f6nnen die Option `--cache-from` verwenden, um das bestehende Image als Cache zu verwenden:\n\n```\ndocker build --cache-from my-app:v1 -t my-app:v2 .\n```\n\nDocker wird dann das bestehende Image `my-app:v1` als Cache verwenden und nur die Schichten neu erstellen, die sich ge\u00e4ndert haben. Dies kann die Build-Zeiten erheblich reduzieren, insbesondere wenn das bestehende Image bereits viele Schichten enth\u00e4lt.\n\nVorteile der Verwendung von `--cache-from`\n\nDie Verwendung der Option `--cache-from` bietet mehrere Vorteile:\n\n1. Schnellere Build-Zeiten: Durch die Verwendung eines externen Caches k\u00f6nnen Sie die Build-Zeiten erheblich reduzieren, da Docker nicht jedes Mal von vorne beginnen muss.\n\n2. Effiziente Nutzung von Ressourcen: Durch die Wiederverwendung bereits erstellter Schichten k\u00f6nnen Sie Ressourcen wie Zeit und Speicherplatz sparen.\n\n3. Konsistente Builds: Durch die Verwendung eines externen Caches k\u00f6nnen Sie sicherstellen, dass Ihre Builds konsistent sind, da sie auf demselben Basis-Image aufbauen.\n\n4. Einfache Aktualisierung von Images: Wenn Sie ein neues Image auf der Grundlage eines bestehenden Images erstellen m\u00f6chten, k\u00f6nnen Sie die Option `--cache-from` verwenden, um den Build-Prozess zu beschleunigen.\n\nFazit\n\nDie Option `--cache-from` ist ein leistungsstarkes Werkzeug, das die Erstellung von Docker-Images beschleunigt, indem es bereits erstellte Schichten wiederverwendet. Durch die Verwendung eines externen Caches k\u00f6nnen Sie die Build-Zeiten erheblich reduzieren und Ressourcen effizient nutzen. Wenn Sie regelm\u00e4\u00dfig Docker-Images erstellen, sollten Sie die Option `--cache-from` in Betracht ziehen, um Ihre Build-Prozesse zu optimieren.","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.jpg","datePublished":"2024-07-23T12:21:35+00:00","dateModified":"2024-07-23T12:23:47+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/"]}]},{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-cache-from_1333.jpg","width":800,"height":600,"caption":"dockerfile-cache-from-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/wiki\/dockerfile-cache-from\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dockerpros.com\/"},{"@type":"ListItem","position":2,"name":"Glossary","item":"https:\/\/dockerpros.com\/fr\/wiki\/"},{"@type":"ListItem","position":3,"name":"Dockerfile &#8211;cache-from"}]},{"@type":"WebSite","@id":"https:\/\/dockerpros.com\/#website","url":"https:\/\/dockerpros.com\/","name":"Docker-Profis","description":"DockerPros \u2013 Ihr umfassender Docker-Ressourcen-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":"de"},{"@type":"Organization","@id":"https:\/\/dockerpros.com\/#organization","name":"Docker-Profis","url":"https:\/\/dockerpros.com\/","logo":{"@type":"ImageObject","inLanguage":"de","@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\/de\/wp-json\/wp\/v2\/glossary\/1333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/glossary"}],"about":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/types\/glossary"}],"author":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":0,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/glossary\/1333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/media\/1979"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/media?parent=1333"}],"wp:term":[{"taxonomy":"glossary-cat","embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/glossary-cat?post=1333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}