{"id":219,"date":"2024-07-21T11:45:28","date_gmt":"2024-07-21T11:45:28","guid":{"rendered":"https:\/\/dockerpros.com\/?p=219"},"modified":"2024-07-21T11:45:28","modified_gmt":"2024-07-21T11:45:28","slug":"how-do-layers-work-in-docker","status":"publish","type":"post","link":"https:\/\/dockerpros.com\/de\/optimization-and-best-practices\/how-do-layers-work-in-docker\/","title":{"rendered":"Wie funktionieren Ebenen in Docker?\n\nDocker verwendet ein Ebenen-Dateisystem, um Images zu erstellen. Jeder Befehl in einer Dockerfile erstellt eine neue Ebene, die auf der vorherigen aufbaut. Wenn Sie ein Image erstellen, werden diese Ebenen zu einem einzigen Image kombiniert. Dies erm\u00f6glicht es, Images effizient zu erstellen und zu teilen, da Ebenen wiederverwendet werden k\u00f6nnen.\n\nWenn Sie ein Container aus einem Image starten, erstellt Docker eine neue Ebene, die als Container-Ebene bezeichnet wird. Diese Ebene ist schreibbar und speichert alle \u00c4nderungen, die w\u00e4hrend der Laufzeit des Containers vorgenommen werden. Wenn der Container gestoppt wird, bleiben diese \u00c4nderungen erhalten, es sei denn, Sie l\u00f6schen den Container.\n\nDocker verwendet ein Copy-on-Write-Schema, um die Effizienz zu maximieren. Wenn eine Datei in einer Ebene ge\u00e4ndert wird, wird sie in die n\u00e4chste Ebene kopiert und dort ge\u00e4ndert. Dies bedeutet, dass die urspr\u00fcngliche Datei in der vorherigen Ebene unver\u00e4ndert bleibt. Dies erm\u00f6glicht es, Images und Container effizient zu speichern und zu verwalten.\n\nZusammenfassend l\u00e4sst sich sagen, dass Ebenen in Docker eine effiziente M\u00f6glichkeit bieten, Images und Container zu erstellen, zu teilen und zu verwalten. Sie erm\u00f6glichen es, Images in kleinere, wiederverwendbare Komponenten aufzuteilen und \u00c4nderungen w\u00e4hrend der Laufzeit von Containern effizient zu speichern."},"content":{"rendered":"<h1>The Intricacies of Docker Layers: A Deep Dive<\/h1>\n<p>Docker has revolutionized the way developers build, ship, and <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> applications. At its core, Docker leverages a unique technology called layered file systems, primarily using a storage mechanism known as union file systems. This article aims to provide an in-depth understanding of how layers work in Docker, the benefits they offer, and practical implications for developers and system administrators alike.<\/p>\n<h2>Understanding Docker Architecture<\/h2>\n<p>Before diving into the specifics of layers, it is essential to grasp the overall architecture of Docker. Docker employs a client-server model:<\/p>\n<ul>\n<li><strong>Docker Client<\/strong>: The command-line interface (CLI) that interacts with the Docker <span class=\"glossaryai-tooltip glossary-term-667\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/daemon\/\" target=\"_blank\">daemon<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A daemon is a background process in computing that runs autonomously, performing tasks without user intervention. It typically handles system or application-level functions, enhancing efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/daemon\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> (server) to issue commands.<\/li>\n<li><strong>Docker <span class=\"glossaryai-tooltip glossary-term-667\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/daemon\/\" target=\"_blank\">Daemon<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A daemon is a background process in computing that runs autonomously, performing tasks without user intervention. It typically handles system or application-level functions, enhancing efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/daemon\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/strong>: The background <span class=\"glossaryai-tooltip glossary-term-681\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/service\/\" target=\"_blank\">service<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Service refers to the act of providing assistance or support to fulfill specific needs or requirements. In various domains, it encompasses customer service, technical support, and professional services, emphasizing efficiency and user satisfaction.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/service\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> that manages Docker containers and images.<\/li>\n<li><strong><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><\/strong>: A <span class=\"glossaryai-tooltip glossary-term-659\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/repository\/\" target=\"_blank\">repository<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A repository is a centralized location where data, code, or documents are stored, managed, and maintained. It facilitates version control, collaboration, and efficient resource sharing among users.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/repository\/\">More \u00bb<\/a><\/span><\/span><span class=\"gai-tooltip-video-wrapper\"><span class=\"gai-tooltip-video\" data-src=\"https:\/\/www.youtube.com\/embed\/_OXj8BGxNPY?rel=0&#038;modestbranding=1\"><\/span><\/span><\/span><\/span><\/span> for storing and distributing Docker images, with <span class=\"glossaryai-tooltip glossary-term-653\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/docker-hub\/\" target=\"_blank\">Docker Hub<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Docker Hub is a cloud-based repository for storing and sharing container images. It facilitates version control, collaborative development, and seamless integration with Docker CLI for efficient container management.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/docker-hub\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> being the most popular public <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>.<\/li>\n<\/ul>\n<p>Docker images are composed of multiple layers, which are critical for efficient storage and data management. Each layer in 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> corresponds to a specific set of filesystem changes, representing changes made at various stages of the build process.<\/p>\n<h2>What Are Docker Layers?<\/h2>\n<p>A Docker layer is essentially a series of filesystem changes that make up 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>. Each layer is immutable, meaning it cannot be changed once created. When you build 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>, 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> creates a new layer. The layers are stacked on top of each other to form the complete <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>.<\/p>\n<h3>The Layering Process<\/h3>\n<ol>\n<li><strong>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><\/strong>: The first layer usually starts from a 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>. This could be an official OS <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> like Ubuntu or a pre-existing application <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><strong>Commands 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\">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><\/strong>: 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> (like <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>) generates a new layer.<\/li>\n<li><strong>Final <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><\/strong>: The final <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 a composite of all these layers stacked together.<\/li>\n<\/ol>\n<p>The layering process not only helps in organizing files and commands but also plays a vital role in optimizing storage and enhancing performance.<\/p>\n<h2>How Layers Work: An Example<\/h2>\n<p>To illustrate the concept of layers, let\u2019s consider a simple <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<pre><code class=\"language-dockerfile\">FROM ubuntu:20.04\nRUN apt-get update &amp;&amp; apt-get install -y python3\nCOPY . \/app\nWORKDIR \/app\nRUN pip install -r requirements.txt\nCMD [\"python3\", \"app.py\"]<\/code><\/pre>\n<h3>Breakdown of Layers<\/h3>\n<ol>\n<li><strong>FROM ubuntu:20.04<\/strong>: This creates the base layer using the Ubuntu <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><strong><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> apt-get update &amp;&amp; apt-get install -y python3<\/strong>: This command generates a new layer with all the changes made by the package manager.<\/li>\n<li><strong><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> . \/app<\/strong>: This adds files from the current directory to the <code>\/app<\/code> directory 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>, creating another layer.<\/li>\n<li><strong><span class=\"glossaryai-tooltip glossary-term-675\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/workdir\/\" target=\"_blank\">WORKDIR<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">The `WORKDIR` instruction in Dockerfile sets the working directory for subsequent instructions. It simplifies path management, as all relative paths will be resolved from this directory, enhancing build clarity.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/workdir\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> \/app<\/strong>: This sets the working directory but does not create a new layer since it does not alter the filesystem.<\/li>\n<li><strong><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> pip install -r requirements.txt<\/strong>: This installs Python packages and creates yet another layer.<\/li>\n<li><strong><span class=\"glossaryai-tooltip glossary-term-670\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/cmd\/\" target=\"_blank\">CMD<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">CMD, or Command Prompt, is a command-line interpreter in Windows operating systems. It allows users to execute commands, automate tasks, and manage system files through a text-based interface.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/cmd\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> [&quot;python3&quot;, &quot;app.py&quot;]<\/strong>: This specifies the command to <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> when a <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/container\/\" target=\"_blank\">container<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is started but does not create a new layer.<\/li>\n<\/ol>\n<p>In this example, we have created a total of four layers, each representing specific changes to the filesystem.<\/p>\n<h2>Benefits of Using Layers<\/h2>\n<h3>1. <strong>Efficiency in Storage<\/strong><\/h3>\n<p>Docker layers optimize storage by allowing multiple images to share layers. For example, if two applications use the same base OS <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 share common dependencies, Docker only needs to store that layer once. This not only saves disk space but also reduces the amount of data transferred over the <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> when pulling images.<\/p>\n<h3>2. <strong>Faster Builds<\/strong><\/h3>\n<p>Layer caching dramatically speeds up the build process. If a layer hasn\u2019t changed since the last build, Docker can use the cached version instead of rebuilding it. This caching mechanism is vital for iterative development, enabling quick adjustments without incurring high build times.<\/p>\n<h3>3. <strong>Version Control<\/strong><\/h3>\n<p>Each layer in 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> can be thought of as a version of the application state at a specific time in the build process. This feature allows developers to roll back to a previous version by choosing an earlier layer, facilitating easy management of application versions.<\/p>\n<h3>4. <strong>Immutable Layers<\/strong><\/h3>\n<p>Once a layer is created, it cannot be altered. This immutability is beneficial in ensuring stability and consistency across different environments. When deploying applications, using immutable layers reduces the risk of discrepancies between development, testing, and production environments.<\/p>\n<h2>Drawbacks of Layered Architecture<\/h2>\n<p>While Docker&#8217;s layered architecture brings many advantages, it is not without drawbacks:<\/p>\n<h3>1. <strong>Complexity in Management<\/strong><\/h3>\n<p>As images accumulate multiple layers, managing and debugging them can become complex. Identifying which layer contributed to a specific issue can be challenging and time-consuming, especially in large applications with many dependencies.<\/p>\n<h3>2. <strong>Performance Overhead<\/strong><\/h3>\n<p>Although layers can speed up builds, they may introduce performance overhead at runtime. Each layer involves a filesystem operation, which can affect <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/container\/\" target=\"_blank\">container<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Containers are lightweight, portable units that encapsulate software and its dependencies, enabling consistent execution across different environments. They leverage OS-level virtualization for efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> startup times, especially if there are many layers to be processed.<\/p>\n<h3>3. <strong><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<\/strong><\/h3>\n<p>Layers <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> to the overall <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. While shared layers reduce duplication, poorly structured Dockerfiles may lead to larger images due to unnecessary layers or large files being added. Best practices, such as minimizing the number of layers and cleaning up temporary files, should be followed to mitigate this issue.<\/p>\n<h2>Best Practices for Managing Docker Layers<\/h2>\n<p>To harness the full potential of Docker layers, developers should consider the following best practices:<\/p>\n<h3>1. <strong>Optimize Layer Count<\/strong><\/h3>\n<p>Minimize the number of layers in your Docker images. Combine commands that can be <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> in a single <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> instruction using <code>&amp;&amp;<\/code> to reduce the number of layers created.<\/p>\n<pre><code class=\"language-dockerfile\"><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> apt-get update &amp;&amp; apt-get install -y python3 &amp;&amp; apt-get clean<\/code><\/pre>\n<h3>2. <strong>Order of Instructions<\/strong><\/h3>\n<p>The order of commands 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> can significantly impact the caching mechanism. Place commands that change less frequently (like installing OS packages) before frequently changing commands (like copying application code).<\/p>\n<h3>3. <strong>Use .dockerignore<\/strong><\/h3>\n<p>Utilize a <code>.dockerignore<\/code> file to exclude unnecessary files and directories from being copied into 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>. This not only helps in reducing the size of the context sent to the Docker <span class=\"glossaryai-tooltip glossary-term-667\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/de\/wiki\/daemon\/\" target=\"_blank\">daemon<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A daemon is a background process in computing that runs autonomously, performing tasks without user intervention. It typically handles system or application-level functions, enhancing efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/de\/wiki\/daemon\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> but also minimizes the number of layers created.<\/p>\n<h3>4. <strong>Remove Temporary Files<\/strong><\/h3>\n<p>If your build process creates temporary files, ensure to remove them in the same <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> command to keep 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> size down.<\/p>\n<h3>5. <strong>Regular Cleanup of Images and Containers<\/strong><\/h3>\n<p>Use <code>docker system prune<\/code> to remove unused images and containers. This action helps maintain an efficient development environment and saves disk space.<\/p>\n<h2>Conclusion<\/h2>\n<p>Docker layers play a fundamental role in the efficiency, scalability, and management of containerized applications. Understanding how layers work, their benefits, and the best practices for managing them can greatly enhance your development workflow and deployment strategy.<\/p>\n<p>By leveraging the advantages of layered architecture while being mindful of its drawbacks, developers can create more efficient, reliable, and maintainable Docker images. As Docker continues to evolve, mastering layers will remain crucial for professionals looking to optimize their containerized applications in an increasingly complex ecosystem.<\/p>","protected":false},"excerpt":{"rendered":"<p>In Docker sind Ebenen Dateisystem\u00e4nderungen, die Images erstellen. Jede Ebene repr\u00e4sentiert eine Anweisung in der <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>, was eine effiziente Speicherung und schnellere <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 mittels Caching.<\/p>","protected":false},"author":1,"featured_media":298,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-219","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-optimization-and-best-practices"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How do layers work in Docker? - Dockerpros<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dockerpros.com\/de\/optimization-and-best-practices\/how-do-layers-work-in-docker\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How do layers work in Docker? - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"In Docker, layers are file system changes that create images. Each layer represents an instruction in the Dockerfile, enabling efficient storage and faster image builds through caching.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/de\/optimization-and-best-practices\/how-do-layers-work-in-docker\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-21T11:45:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"dockerpros\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"dockerpros\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"6\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/\"},\"author\":{\"name\":\"dockerpros\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4\"},\"headline\":\"How do layers work in Docker?\",\"datePublished\":\"2024-07-21T11:45:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/\"},\"wordCount\":1072,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dockerpros.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg\",\"articleSection\":[\"Optimization and Best Practices\"],\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/\",\"url\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/\",\"name\":\"How do layers work in Docker? - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg\",\"datePublished\":\"2024-07-21T11:45:28+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg\",\"width\":800,\"height\":600,\"caption\":\"how-do-layers-work-in-docker-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dockerpros.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How do layers work in Docker?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dockerpros.com\/#website\",\"url\":\"https:\/\/dockerpros.com\/\",\"name\":\"Dockerpros\",\"description\":\"DockerPros \u2013 Your Ultimate Docker Resource Hub\",\"publisher\":{\"@id\":\"https:\/\/dockerpros.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dockerpros.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"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\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4\",\"name\":\"dockerpros\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1780577253\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1780577253\",\"caption\":\"dockerpros\"},\"sameAs\":[\"https:\/\/dockerpros.com\/\"],\"url\":\"https:\/\/dockerpros.com\/de\/author\/dockerpros\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Wie funktionieren Ebenen in Docker? - Dockerpros\n\nDocker ist eine Open-Source-Plattform, die es Entwicklern erm\u00f6glicht, Anwendungen in Containern zu erstellen, bereitzustellen und auszuf\u00fchren. Docker verwendet ein Schichtsystem, um Images zu erstellen und zu verwalten. In diesem Artikel werden wir uns ansehen, wie Ebenen in Docker funktionieren und wie sie zur Erstellung von Images verwendet werden.\n\nWas sind Ebenen in Docker?\n\nIn Docker ist ein Image eine schreibgesch\u00fctzte Vorlage, die zum Erstellen von Containern verwendet wird. Ein Image besteht aus einer oder mehreren Ebenen, wobei jede Ebene eine Reihe von Anweisungen darstellt, die ausgef\u00fchrt werden, um das Image zu erstellen. Jede Ebene ist eine schreibgesch\u00fctzte Datei, die die Ergebnisse der Ausf\u00fchrung der Anweisungen in dieser Ebene enth\u00e4lt.\n\nWenn Sie ein Docker-Image erstellen, erstellen Sie im Wesentlichen eine Reihe von Ebenen, die \u00fcbereinander gestapelt sind. Jede Ebene ist eine schreibgesch\u00fctzte Datei, die die Ergebnisse der Ausf\u00fchrung der Anweisungen in dieser Ebene enth\u00e4lt. Wenn Sie einen Container aus einem Image erstellen, erstellt Docker eine schreibbare Ebene auf der obersten Ebene des Images. Diese schreibbare Ebene wird als Container-Ebene bezeichnet.\n\nWie funktionieren Ebenen in Docker?\n\nDocker verwendet ein Union-Dateisystem, um Ebenen zu verwalten. Ein Union-Dateisystem erm\u00f6glicht es, mehrere Dateisysteme zu einem einzigen zusammenzuf\u00fchren. In Docker wird jede Ebene als separates Dateisystem behandelt, und das Union-Dateisystem kombiniert sie zu einem einzigen Dateisystem.\n\nWenn Sie einen Container aus einem Image erstellen, erstellt Docker eine schreibbare Ebene auf der obersten Ebene des Images. Diese schreibbare Ebene wird als Container-Ebene bezeichnet. Alle \u00c4nderungen, die am Container vorgenommen werden, werden in dieser Ebene gespeichert. Wenn der Container gel\u00f6scht wird, wird auch die Container-Ebene gel\u00f6scht.\n\nWenn Sie ein Docker-Image erstellen, erstellen Sie im Wesentlichen eine Reihe von Ebenen, die \u00fcbereinander gestapelt sind. Jede Ebene ist eine schreibgesch\u00fctzte Datei, die die Ergebnisse der Ausf\u00fchrung der Anweisungen in dieser Ebene enth\u00e4lt. Wenn Sie einen Container aus einem Image erstellen, erstellt Docker eine schreibbare Ebene auf der obersten Ebene des Images.\n\nVorteile der Verwendung von Ebenen in Docker\n\nDie Verwendung von Ebenen in Docker bietet mehrere Vorteile:\n\n1. Effizienz: Da jede Ebene eine schreibgesch\u00fctzte Datei ist, k\u00f6nnen mehrere Container das gleiche Image teilen. Dies reduziert die Menge an Speicherplatz, die zum Speichern von Images ben\u00f6tigt wird.\n\n2. Geschwindigkeit: Da jede Ebene eine schreibgesch\u00fctzte Datei ist, kann Docker \u00c4nderungen an einer Ebene vornehmen, ohne die anderen Ebenen zu beeinflussen. Dies macht es schnell und effizient, \u00c4nderungen an einem Image vorzunehmen.\n\n3. Wiederverwendbarkeit: Da jede Ebene eine schreibgesch\u00fctzte Datei ist, k\u00f6nnen Sie Ebenen in mehreren Images wiederverwenden. Dies macht es einfach, Images zu erstellen, die gemeinsame Abh\u00e4ngigkeiten haben.\n\nFazit\n\nZusammenfassend l\u00e4sst sich sagen, dass Ebenen ein grundlegender Bestandteil von Docker sind. Sie erm\u00f6glichen es Ihnen, Images effizient zu erstellen und zu verwalten, und sie bieten mehrere Vorteile, darunter Effizienz, Geschwindigkeit und Wiederverwendbarkeit. Wenn Sie mit Docker arbeiten, ist es wichtig, zu verstehen, wie Ebenen funktionieren und wie sie zur Erstellung von Images verwendet werden.","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\/optimization-and-best-practices\/how-do-layers-work-in-docker\/","og_locale":"de_DE","og_type":"article","og_title":"How do layers work in Docker? - Dockerpros","og_description":"In Docker, layers are file system changes that create images. Each layer represents an instruction in the Dockerfile, enabling efficient storage and faster image builds through caching.","og_url":"https:\/\/dockerpros.com\/de\/optimization-and-best-practices\/how-do-layers-work-in-docker\/","og_site_name":"Dockerpros","article_published_time":"2024-07-21T11:45:28+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg","type":"image\/jpeg"}],"author":"dockerpros","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"dockerpros","Gesch\u00e4tzte Lesezeit":"6\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#article","isPartOf":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/"},"author":{"name":"dockerpros","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4"},"headline":"How do layers work in Docker?","datePublished":"2024-07-21T11:45:28+00:00","mainEntityOfPage":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/"},"wordCount":1072,"commentCount":0,"publisher":{"@id":"https:\/\/dockerpros.com\/#organization"},"image":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg","articleSection":["Optimization and Best Practices"],"inLanguage":"de","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/","url":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/","name":"Wie funktionieren Ebenen in Docker? - Dockerpros\n\nDocker ist eine Open-Source-Plattform, die es Entwicklern erm\u00f6glicht, Anwendungen in Containern zu erstellen, bereitzustellen und auszuf\u00fchren. Docker verwendet ein Schichtsystem, um Images zu erstellen und zu verwalten. In diesem Artikel werden wir uns ansehen, wie Ebenen in Docker funktionieren und wie sie zur Erstellung von Images verwendet werden.\n\nWas sind Ebenen in Docker?\n\nIn Docker ist ein Image eine schreibgesch\u00fctzte Vorlage, die zum Erstellen von Containern verwendet wird. Ein Image besteht aus einer oder mehreren Ebenen, wobei jede Ebene eine Reihe von Anweisungen darstellt, die ausgef\u00fchrt werden, um das Image zu erstellen. Jede Ebene ist eine schreibgesch\u00fctzte Datei, die die Ergebnisse der Ausf\u00fchrung der Anweisungen in dieser Ebene enth\u00e4lt.\n\nWenn Sie ein Docker-Image erstellen, erstellen Sie im Wesentlichen eine Reihe von Ebenen, die \u00fcbereinander gestapelt sind. Jede Ebene ist eine schreibgesch\u00fctzte Datei, die die Ergebnisse der Ausf\u00fchrung der Anweisungen in dieser Ebene enth\u00e4lt. Wenn Sie einen Container aus einem Image erstellen, erstellt Docker eine schreibbare Ebene auf der obersten Ebene des Images. Diese schreibbare Ebene wird als Container-Ebene bezeichnet.\n\nWie funktionieren Ebenen in Docker?\n\nDocker verwendet ein Union-Dateisystem, um Ebenen zu verwalten. Ein Union-Dateisystem erm\u00f6glicht es, mehrere Dateisysteme zu einem einzigen zusammenzuf\u00fchren. In Docker wird jede Ebene als separates Dateisystem behandelt, und das Union-Dateisystem kombiniert sie zu einem einzigen Dateisystem.\n\nWenn Sie einen Container aus einem Image erstellen, erstellt Docker eine schreibbare Ebene auf der obersten Ebene des Images. Diese schreibbare Ebene wird als Container-Ebene bezeichnet. Alle \u00c4nderungen, die am Container vorgenommen werden, werden in dieser Ebene gespeichert. Wenn der Container gel\u00f6scht wird, wird auch die Container-Ebene gel\u00f6scht.\n\nWenn Sie ein Docker-Image erstellen, erstellen Sie im Wesentlichen eine Reihe von Ebenen, die \u00fcbereinander gestapelt sind. Jede Ebene ist eine schreibgesch\u00fctzte Datei, die die Ergebnisse der Ausf\u00fchrung der Anweisungen in dieser Ebene enth\u00e4lt. Wenn Sie einen Container aus einem Image erstellen, erstellt Docker eine schreibbare Ebene auf der obersten Ebene des Images.\n\nVorteile der Verwendung von Ebenen in Docker\n\nDie Verwendung von Ebenen in Docker bietet mehrere Vorteile:\n\n1. Effizienz: Da jede Ebene eine schreibgesch\u00fctzte Datei ist, k\u00f6nnen mehrere Container das gleiche Image teilen. Dies reduziert die Menge an Speicherplatz, die zum Speichern von Images ben\u00f6tigt wird.\n\n2. Geschwindigkeit: Da jede Ebene eine schreibgesch\u00fctzte Datei ist, kann Docker \u00c4nderungen an einer Ebene vornehmen, ohne die anderen Ebenen zu beeinflussen. Dies macht es schnell und effizient, \u00c4nderungen an einem Image vorzunehmen.\n\n3. Wiederverwendbarkeit: Da jede Ebene eine schreibgesch\u00fctzte Datei ist, k\u00f6nnen Sie Ebenen in mehreren Images wiederverwenden. Dies macht es einfach, Images zu erstellen, die gemeinsame Abh\u00e4ngigkeiten haben.\n\nFazit\n\nZusammenfassend l\u00e4sst sich sagen, dass Ebenen ein grundlegender Bestandteil von Docker sind. Sie erm\u00f6glichen es Ihnen, Images effizient zu erstellen und zu verwalten, und sie bieten mehrere Vorteile, darunter Effizienz, Geschwindigkeit und Wiederverwendbarkeit. Wenn Sie mit Docker arbeiten, ist es wichtig, zu verstehen, wie Ebenen funktionieren und wie sie zur Erstellung von Images verwendet werden.","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg","datePublished":"2024-07-21T11:45:28+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/"]}]},{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-layers-work-in-docker_219.jpg","width":800,"height":600,"caption":"how-do-layers-work-in-docker-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-layers-work-in-docker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dockerpros.com\/"},{"@type":"ListItem","position":2,"name":"How do layers work in Docker?"}]},{"@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\/"}},{"@type":"Person","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4","name":"dockerpros","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/image\/","url":"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1780577253","contentUrl":"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1780577253","caption":"dockerpros"},"sameAs":["https:\/\/dockerpros.com\/"],"url":"https:\/\/dockerpros.com\/de\/author\/dockerpros\/"}]}},"_links":{"self":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/posts\/219","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/comments?post=219"}],"version-history":[{"count":0,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/posts\/219\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/media\/298"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/media?parent=219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/categories?post=219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dockerpros.com\/de\/wp-json\/wp\/v2\/tags?post=219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}