{"id":1356,"date":"2024-07-23T12:38:05","date_gmt":"2024-07-23T12:38:05","guid":{"rendered":"https:\/\/dockerpros.com\/?post_type=glossary&#038;p=1356"},"modified":"2024-07-23T12:38:05","modified_gmt":"2024-07-23T12:38:05","slug":"dockerfile-import-cache","status":"publish","type":"glossary","link":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/","title":{"rendered":"Dockerfile \u2013import-cache"},"content":{"rendered":"<h1>Understanding Dockerfile &#8211;import-cache: A Deep Dive<\/h1>\n<p>The <code>--import-cache<\/code> option in Docker is an advanced feature that enables users to optimize their <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> build process significantly by importing cache from external sources. This command enhances the efficiency of building Docker images by utilizing previously cached layers, allowing developers to save time and resources when constructing complex applications. In this article, we will explore the inner workings of <code>--import-cache<\/code>, its advantages, and practical use cases, along with a detailed look at how to effectively implement it within your own Docker workflows.<\/p>\n<h2>The Importance of Caching in Docker Builds<\/h2>\n<p>Before diving into the specifics of <code>--import-cache<\/code>, it&#8217;s essential to understand the concept of caching in Docker builds. Docker uses a layered filesystem to efficiently manage images. Each instruction in a <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> results in 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, which can be cached. 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 if the preceding layers have changed. If they haven&#8217;t, Docker reuses the cached layers instead of recreating them, which can significantly reduce build times.<\/p>\n<h3>How Caching Works in Docker<\/h3>\n<ol>\n<li><strong>Layer Creation<\/strong>: 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>, Docker reads 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> and executes each instruction sequentially, creating a new layer for each step.<\/li>\n<li><strong>Layer Caching<\/strong>: After a layer is created, Docker caches it. If the same instruction is encountered in a subsequent build and the context hasn\u2019t changed, Docker can use the cached layer instead of re-executing the command.<\/li>\n<li><strong>Cache Invalidation<\/strong>: If any file or line that a layer depends on changes, Docker invalidates that layer and all subsequent layers. This means that even small changes can lead to longer build times if there are many layers 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>.<\/li>\n<\/ol>\n<h2>What is &#8211;import-cache?<\/h2>\n<p>The <code>--import-cache<\/code> option allows you to bring in cached layers from another build context or a remote cache. This is particularly useful when you are working in a team environment or across multiple CI\/CD pipelines where maintaining consistent build times is crucial. By leveraging existing cached layers, you can drastically reduce the time it takes to build Docker images, especially when dependencies or environment configurations remain relatively stable.<\/p>\n<h3>The Syntax<\/h3>\n<p>The general syntax for using <code>--import-cache<\/code> is as follows:<\/p>\n<pre><code class=\"language-bash\">docker build --import-cache= -t  <\/code><\/pre>\n<ul>\n<li>&#8220;: This is the local path or the remote cache location from which cached layers will be imported.<\/li>\n<li>&#8220;: This is the name you want to give to your resulting 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>.<\/li>\n<li>&#8220;: This is the path to your <span class=\"glossaryai-tooltip glossary-term-1243\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/docker-build-context\/\" target=\"_blank\">Docker build context<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Docker build context refers to the files and directories available during the image build process. It is crucial for accessing application code and dependencies, influencing efficiency and security.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/docker-build-context\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, typically where your <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> is located.<\/li>\n<\/ul>\n<h2>Why Use &#8211;import-cache?<\/h2>\n<h3>1. Improve Build Times<\/h3>\n<p>One of the primary benefits of <code>--import-cache<\/code> is the reduction in build times. When working with large applications that have numerous dependencies, the build process can become time-consuming. By importing cached layers, you can bypass the time-consuming steps that have not changed, leading to faster iterations during development.<\/p>\n<h3>2. Enhance CI\/CD Efficiency<\/h3>\n<p>In Continuous Integration\/Continuous Deployment (CI\/CD) environments, where builds are triggered frequently, leveraging <code>--import-cache<\/code> can improve the overall efficiency of the pipeline. By utilizing previously built layers, teams can ensure that they are not wasting resources or time rebuilding layers that have already been constructed.<\/p>\n<h3>3. Maintain Consistency Across Environments<\/h3>\n<p>Using <code>--import-cache<\/code> helps ensure that builds across different environments (such as local development, staging, and production) are consistent. This can minimize the chances of &quot;works on my machine&quot; issues by ensuring that the same cached layers are utilized across all environments.<\/p>\n<h3>4. Reduce Network Overhead<\/h3>\n<p>When working with large images or extensive repositories of dependencies, transferring these layers can become a bottleneck. By importing cache locally, you can mitigate <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> overhead, leading to a more efficient build process, especially when working in environments with limited bandwidth.<\/p>\n<h2>Implementing &#8211;import-cache: A Step-by-Step Guide<\/h2>\n<p>Let&#8217;s take a closer look at how to implement <code>--import-cache<\/code> in your Docker workflows.<\/p>\n<h3>Step 1: Prepare Your Dockerfile<\/h3>\n<p>Before you can utilize <code>--import-cache<\/code>, ensure you have a well-structured <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>. Here\u2019s a simple example:<\/p>\n<pre><code class=\"language-dockerfile\"># Use an official Python runtime as a parent image\nFROM python:3.9-slim\n\n# Set the working directory\nWORKDIR \/app\n\n# Copy requirements.txt to the working directory\nCOPY requirements.txt .\n\n# Install any needed packages specified in requirements.txt\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy the rest of the application code\nCOPY . .\n\n# Run the application\nCMD [\"python\", \"app.py\"]<\/code><\/pre>\n<h3>Step 2: Build Your Image Without Cache<\/h3>\n<p>First, build your <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> normally to create a cache. This initial build will serve as the source of your imported cache.<\/p>\n<pre><code class=\"language-bash\">docker build -t myapp:latest .<\/code><\/pre>\n<h3>Step 3: Make Changes to Your Code<\/h3>\n<p>Modify a file in your application, such as <code>app.py<\/code> or <code>requirements.txt<\/code>. This change will invalidate the cache for the subsequent build.<\/p>\n<h3>Step 4: Use &#8211;import-cache to Optimize the Build<\/h3>\n<p>Now you can use the <code>--import-cache<\/code> option to import the cached layers while building 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>. You can use a local directory or a remote cache.<\/p>\n<p>For a local directory (assuming you have exported the cache to a folder called <code>cache<\/code>):<\/p>\n<pre><code class=\"language-bash\">docker build --import-cache=cache -t myapp:latest .<\/code><\/pre>\n<p>If you are using a remote cache, you might reference it like so (assuming you have set up a <span class=\"glossaryai-tooltip glossary-term-736\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/docker-registry\/\" target=\"_blank\">Docker Registry<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A Docker Registry is a storage and distribution system for Docker images. It allows developers to upload, manage, and share container images, facilitating efficient deployment in diverse environments.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/docker-registry\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>):<\/p>\n<pre><code class=\"language-bash\">docker build --import-cache=myregistry\/myapp:cache -t myapp:latest .<\/code><\/pre>\n<h3>Step 5: Verify the Build Process<\/h3>\n<p>After running the build with <code>--import-cache<\/code>, check the build logs to ensure that layers were reused from the cache. You should see log messages indicating that cached layers were used, which confirms that the process worked correctly.<\/p>\n<h2>Best Practices for Using &#8211;import-cache<\/h2>\n<h3>1. Structure Your Dockerfile Wisely<\/h3>\n<p>Ensure that your <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> is structured to take full advantage of caching. Place commands that are least likely to change towards the top of the file, such as 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> declarations and package installations, while keeping application code and frequently changing files towards the bottom.<\/p>\n<h3>2. Use Versioned Images<\/h3>\n<p>When importing caches from a remote source, consider using versioned images. This helps manage dependencies and ensures that you are maintaining a consistent environment across builds.<\/p>\n<h3>3. Clean Up Unused Cache<\/h3>\n<p>Regularly clean up unused cache layers to save disk space and maintain optimal performance. You can do this by using the <code>docker builder prune<\/code> command.<\/p>\n<h3>4. Monitor Build Performance<\/h3>\n<p>Utilize Docker&#8217;s BuildKit, which can provide insights into the performance of your builds. By enabling BuildKit, you can gather metrics on cache hits and misses, allowing you to optimize your build process further.<\/p>\n<h2>Troubleshooting Common Issues<\/h2>\n<h3>1. Cache Not Being Used<\/h3>\n<p>If you notice that the cache is not being utilized as expected, check the following:<\/p>\n<ul>\n<li>Ensure that the context has not changed in a way that invalidates the cache.<\/li>\n<li>Verify that you are pointing to the correct cache location.<\/li>\n<li>Check Docker&#8217;s build context to ensure that there are no discrepancies.<\/li>\n<\/ul>\n<h3>2. Inconsistent Builds<\/h3>\n<p>In cases where builds are inconsistent, consider:<\/p>\n<ul>\n<li>Verifying that all dependencies are explicitly defined in your <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>.<\/li>\n<li>Ensuring your build environments are similar. Differences in the environment can affect the way dependencies are resolved.<\/li>\n<\/ul>\n<h3>3. Performance Bottlenecks<\/h3>\n<p>Should you encounter performance issues, consider analyzing where the build process is slowed down. Using verbose logging can help identify which steps are taking the most time, allowing you to focus your optimization efforts effectively.<\/p>\n<h2>Conclusion<\/h2>\n<p>The <code>--import-cache<\/code> option in Docker is a powerful feature that can significantly optimize your <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> build processes. By leveraging cached layers from previous builds, teams can save time, reduce resource usage, and maintain consistency across environments. Understanding and implementing this feature effectively can lead to better workflows and improved software delivery processes.<\/p>\n<p>As you continue to explore the world of Docker and containerization, consider incorporating <code>--import-cache<\/code> into your build strategies. With its ability to streamline your builds and enhance CI\/CD pipelines, this advanced Docker feature is essential for any developer or DevOps engineer looking to maximize efficiency in their containerized applications.<\/p>","protected":false},"excerpt":{"rendered":"<p>Die `\u2013import-cache`-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> erleichtert effiziente <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/image\/\" target=\"_blank\">Bild<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Ein Bild ist eine visuelle Darstellung eines Objekts oder einer Szene, die typischerweise aus Pixeln in digitalen Formaten besteht. Es kann Informationen vermitteln, Emotionen hervorrufen und die Kommunikation \u00fcber verschiedene Medien hinweg erleichtern.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> builds by allowing the importation of existing cache layers. This feature enhances build speed, reduces redundancy, and optimizes resource utilization.<\/p>","protected":false},"author":1,"featured_media":2025,"parent":0,"template":"","glossary-cat":[],"class_list":["post-1356","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 -import-cache - Dockerpros<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dockerfile -import-cache - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"The `--import-cache` option in Dockerfile facilitates efficient image builds by allowing the importation of existing cache layers. This feature enhances build speed, reduces redundancy, and optimizes resource utilization.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.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=\"6\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/\",\"url\":\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/\",\"name\":\"Dockerfile -import-cache - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.jpg\",\"datePublished\":\"2024-07-23T12:38:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.jpg\",\"width\":800,\"height\":600,\"caption\":\"dockerfile-import-cache-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dockerpros.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Glossary\",\"item\":\"https:\/\/dockerpros.com\/fr\/wiki\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Dockerfile &#8211;import-cache\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dockerpros.com\/#website\",\"url\":\"https:\/\/dockerpros.com\/\",\"name\":\"Dockerpros\",\"description\":\"DockerPros \u2013 Your Ultimate Docker Resource Hub\",\"publisher\":{\"@id\":\"https:\/\/dockerpros.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dockerpros.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"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 -import-cache - Dockerpros\n\nIn diesem Artikel werden wir uns mit der Verwendung des -import-cache-Flags in Dockerfiles befassen. Dieses Flag erm\u00f6glicht es uns, den Build-Cache beim Importieren von Images zu nutzen, was zu erheblichen Zeitersparnissen f\u00fchren kann.\n\nWas ist der Build-Cache?\n------------------------\n\nBevor wir uns mit dem -import-cache-Flag befassen, ist es wichtig zu verstehen, was der Build-Cache ist. Der Build-Cache ist ein Mechanismus in Docker, der es erm\u00f6glicht, bereits erstellte Image-Schichten wiederzuverwenden. Wenn Sie ein Dockerfile erstellen und einen Befehl ausf\u00fchren, der eine neue Schicht erstellt, speichert Docker diese Schicht im Cache. Wenn Sie das Dockerfile erneut ausf\u00fchren und der Befehl unver\u00e4ndert ist, verwendet Docker die zwischengespeicherte Schicht anstelle der erneuten Ausf\u00fchrung des Befehls.\n\nDas -import-cache-Flag\n----------------------\n\nDas -import-cache-Flag ist ein neues Feature in Docker 20.10, das es erm\u00f6glicht, den Build-Cache beim Importieren von Images zu nutzen. Wenn Sie ein Image importieren, das aus einem Dockerfile erstellt wurde, das den Build-Cache verwendet hat, k\u00f6nnen Sie das -import-cache-Flag verwenden, um den Cache beim Importieren des Images zu nutzen. Dies kann zu erheblichen Zeitersparnissen f\u00fchren, da Docker nicht alle Schichten erneut erstellen muss.\n\nVerwendung des -import-cache-Flags\n----------------------------------\n\nUm das -import-cache-Flag zu verwenden, m\u00fcssen Sie das Image mit dem Flag importieren. Hier ist ein Beispiel:\n\n```\ndocker import -import-cache my-image.tar\n```\n\nIn diesem Beispiel importieren wir ein Image namens \"my-image.tar\" und verwenden das -import-cache-Flag, um den Build-Cache zu nutzen.\n\nVorteile des -import-cache-Flags\n--------------------------------\n\nDas -import-cache-Flag bietet mehrere Vorteile:\n\n1. Zeitersparnis: Durch die Nutzung des Build-Caches kann Docker Zeit sparen, da es nicht alle Schichten erneut erstellen muss.\n\n2. Konsistenz: Wenn Sie ein Image importieren, das aus einem Dockerfile erstellt wurde, das den Build-Cache verwendet hat, k\u00f6nnen Sie sicher sein, dass das importierte Image identisch mit dem Original ist.\n\n3. Flexibilit\u00e4t: Das -import-cache-Flag erm\u00f6glicht es Ihnen, den Build-Cache beim Importieren von Images zu nutzen, was besonders n\u00fctzlich ist, wenn Sie Images von externen Quellen importieren.\n\nFazit\n-----\n\nDas -import-cache-Flag ist ein n\u00fctzliches Feature in Docker 20.10, das es erm\u00f6glicht, den Build-Cache beim Importieren von Images zu nutzen. Durch die Nutzung des Build-Caches kann Docker Zeit sparen und sicherstellen, dass importierte Images identisch mit dem Original sind. Wenn Sie h\u00e4ufig Images importieren, sollten Sie das -import-cache-Flag in Betracht ziehen, um Zeit und Ressourcen zu sparen.","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-import-cache\/","og_locale":"de_DE","og_type":"article","og_title":"Dockerfile -import-cache - Dockerpros","og_description":"The `--import-cache` option in Dockerfile facilitates efficient image builds by allowing the importation of existing cache layers. This feature enhances build speed, reduces redundancy, and optimizes resource utilization.","og_url":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/","og_site_name":"Dockerpros","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Gesch\u00e4tzte Lesezeit":"6\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/","url":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/","name":"Dockerfile -import-cache - Dockerpros\n\nIn diesem Artikel werden wir uns mit der Verwendung des -import-cache-Flags in Dockerfiles befassen. Dieses Flag erm\u00f6glicht es uns, den Build-Cache beim Importieren von Images zu nutzen, was zu erheblichen Zeitersparnissen f\u00fchren kann.\n\nWas ist der Build-Cache?\n------------------------\n\nBevor wir uns mit dem -import-cache-Flag befassen, ist es wichtig zu verstehen, was der Build-Cache ist. Der Build-Cache ist ein Mechanismus in Docker, der es erm\u00f6glicht, bereits erstellte Image-Schichten wiederzuverwenden. Wenn Sie ein Dockerfile erstellen und einen Befehl ausf\u00fchren, der eine neue Schicht erstellt, speichert Docker diese Schicht im Cache. Wenn Sie das Dockerfile erneut ausf\u00fchren und der Befehl unver\u00e4ndert ist, verwendet Docker die zwischengespeicherte Schicht anstelle der erneuten Ausf\u00fchrung des Befehls.\n\nDas -import-cache-Flag\n----------------------\n\nDas -import-cache-Flag ist ein neues Feature in Docker 20.10, das es erm\u00f6glicht, den Build-Cache beim Importieren von Images zu nutzen. Wenn Sie ein Image importieren, das aus einem Dockerfile erstellt wurde, das den Build-Cache verwendet hat, k\u00f6nnen Sie das -import-cache-Flag verwenden, um den Cache beim Importieren des Images zu nutzen. Dies kann zu erheblichen Zeitersparnissen f\u00fchren, da Docker nicht alle Schichten erneut erstellen muss.\n\nVerwendung des -import-cache-Flags\n----------------------------------\n\nUm das -import-cache-Flag zu verwenden, m\u00fcssen Sie das Image mit dem Flag importieren. Hier ist ein Beispiel:\n\n```\ndocker import -import-cache my-image.tar\n```\n\nIn diesem Beispiel importieren wir ein Image namens \"my-image.tar\" und verwenden das -import-cache-Flag, um den Build-Cache zu nutzen.\n\nVorteile des -import-cache-Flags\n--------------------------------\n\nDas -import-cache-Flag bietet mehrere Vorteile:\n\n1. Zeitersparnis: Durch die Nutzung des Build-Caches kann Docker Zeit sparen, da es nicht alle Schichten erneut erstellen muss.\n\n2. Konsistenz: Wenn Sie ein Image importieren, das aus einem Dockerfile erstellt wurde, das den Build-Cache verwendet hat, k\u00f6nnen Sie sicher sein, dass das importierte Image identisch mit dem Original ist.\n\n3. Flexibilit\u00e4t: Das -import-cache-Flag erm\u00f6glicht es Ihnen, den Build-Cache beim Importieren von Images zu nutzen, was besonders n\u00fctzlich ist, wenn Sie Images von externen Quellen importieren.\n\nFazit\n-----\n\nDas -import-cache-Flag ist ein n\u00fctzliches Feature in Docker 20.10, das es erm\u00f6glicht, den Build-Cache beim Importieren von Images zu nutzen. Durch die Nutzung des Build-Caches kann Docker Zeit sparen und sicherstellen, dass importierte Images identisch mit dem Original sind. Wenn Sie h\u00e4ufig Images importieren, sollten Sie das -import-cache-Flag in Betracht ziehen, um Zeit und Ressourcen zu sparen.","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.jpg","datePublished":"2024-07-23T12:38:05+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/"]}]},{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/dockerfile-import-cache_1356.jpg","width":800,"height":600,"caption":"dockerfile-import-cache-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/de\/wiki\/dockerfile-import-cache\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dockerpros.com\/"},{"@type":"ListItem","position":2,"name":"Glossary","item":"https:\/\/dockerpros.com\/fr\/wiki\/"},{"@type":"ListItem","position":3,"name":"Dockerfile &#8211;import-cache"}]},{"@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\/1356","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\/1356\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/media\/2025"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/media?parent=1356"}],"wp:term":[{"taxonomy":"glossary-cat","embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/glossary-cat?post=1356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}