{"id":220,"date":"2024-07-21T11:45:27","date_gmt":"2024-07-21T11:45:27","guid":{"rendered":"https:\/\/dockerpros.com\/?p=220"},"modified":"2024-07-21T11:45:27","modified_gmt":"2024-07-21T11:45:27","slug":"para-reducir-el-tamano-de-las-imagenes-de-docker-puedes-seguir-estos-pasos1-utiliza-una-imagen-base-mas-pequena-en-lugar-de-usar-imagenes-base-grandes-como-ubuntu-o-centos-considera-usar-imagen","status":"publish","type":"post","link":"https:\/\/dockerpros.com\/es\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/","title":{"rendered":"How do I reduce the size of Docker images?"},"content":{"rendered":"<h1>How to Reduce the Size of Docker Images: Techniques and Best Practices<\/h1>\n<p>Docker has revolutionized the software development process by allowing developers to package applications and their dependencies into containers. However, as the use of Docker has grown, so has the concern about the size of Docker images. Larger images can lead to increased storage costs, slower deployment times, and longer build processes. In this article, we will explore advanced techniques and best practices for reducing the size of Docker images, ensuring more efficient resource usage.<\/p>\n<h2>Understanding Docker Image Layers<\/h2>\n<p>Before diving into the strategies for reducing Docker <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> sizes, it is essential to understand how Docker images are constructed. Docker images are made up of a series of read-only layers. Each layer represents a set of changes made to the previous layer and is created from a command in the <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. When you build an <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, Docker caches each layer to speed up subsequent builds. <\/p>\n<p>The layers are stored as a union filesystem, meaning that only the differences between layers are stored on disk. This makes it possible to share layers across different images. However, it also means that a poorly constructed <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> can lead to unnecessarily large images with many redundant layers.<\/p>\n<h2>Best Practices for Reducing Docker Image Sizes<\/h2>\n<h3>1. Choose the Right Base Image<\/h3>\n<p>The choice of base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> significantly impacts the size of your final Docker <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. Using a minimal base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> can lead to smaller images overall. For example, instead of using <code>ubuntu<\/code> or <code>alpine<\/code>, consider using an even smaller base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> like <code>scratch<\/code>. If you require more features, <code>alpine<\/code> is a popular choice as it is much smaller than traditional distributions.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-dockerfile\">FROM alpine:3.15<\/code><\/pre>\n<h3>2. Minimize the Number of Layers<\/h3>\n<p>Each instruction in a <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> creates a new layer. To reduce the final <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> size, combine commands where possible. You can achieve this by chaining commands in a single <code><span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code> instruction.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-dockerfile\"><span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> apt-get update &amp;&amp; \n    apt-get install -y package1 package2 package3 &amp;&amp; \n    apt-get clean &amp;&amp; \n    rm -rf \/var\/lib\/apt\/lists\/*<\/code><\/pre>\n<p>This example runs the <code>apt-get<\/code> commands in a single layer, reducing the number of layers created.<\/p>\n<h3>3. Use Multi-Stage Builds<\/h3>\n<p>Multi-stage builds allow you to separate the build environment from the production environment. You can use one stage to compile your application and another to create a smaller <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> with only the necessary artifacts.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-dockerfile\"># Build stage\nFROM golang:1.17 AS builder\nWORKDIR \/app\nCOPY . .\nRUN go build -o myapp\n\n# Production stage\nFROM alpine:3.15\nWORKDIR \/app\nCOPY --from=builder \/app\/myapp .\nCMD [\".\/myapp\"]<\/code><\/pre>\n<p>In this example, the final <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> contains only the compiled binary, significantly reducing the size.<\/p>\n<h3>4. Clean Up After Installation<\/h3>\n<p>When installing packages, temporary files and caches are often left behind, contributing unnecessary weight to the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. Always clean up after installation by removing caches or unnecessary files.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-dockerfile\"><span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> apt-get update &amp;&amp; \n    apt-get install -y package1 &amp;&amp; \n    apt-get clean &amp;&amp; \n    rm -rf \/var\/lib\/apt\/lists\/*<\/code><\/pre>\n<h3>5. Use <code>.dockerignore<\/code> File<\/h3>\n<p>The <code>.dockerignore<\/code> file is used to exclude files and directories from the build context. This helps prevent unnecessary files from being copied into the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, keeping it lean.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code>node_modules\n*.log\nDockerfile\n.git<\/code><\/pre>\n<h3>6. Optimize Application Dependencies<\/h3>\n<p>Review your application dependencies to ensure that no unnecessary packages are included in your <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This is particularly important for languages like <span class=\"glossaryai-tooltip glossary-term-684\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/node\/\" target=\"_blank\">Node<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Node, or Node.js, is a JavaScript runtime built on Chrome's V8 engine, enabling server-side scripting. It allows developers to build scalable network applications using asynchronous, event-driven architecture.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/node\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.js or Python, where dependencies can be extensive. Use tools like <code>npm prune<\/code> or <code>pip freeze<\/code> to keep your dependencies in check.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-dockerfile\"># Node.js Example\nFROM node:14\nWORKDIR \/app\nCOPY package.json package-lock.json .\/\nRUN npm install --production\nCOPY . .\nCMD [\"node\", \"server.js\"]<\/code><\/pre>\n<h3>7. Compress Your Images<\/h3>\n<p>Docker supports <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> compression, which can help reduce the size of the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> on disk. The <code>docker build<\/code> command can use compression when creating images. To enable compression, you can pass the <code>--compress<\/code> flag.<\/p>\n<pre><code class=\"language-bash\">docker build --compress -t myimage:latest .<\/code><\/pre>\n<h3>8. Use Specific Tags for Base Images<\/h3>\n<p>When specifying base images, always use specific version numbers or tags instead of <code>latest<\/code>. This practice not only helps with reproducibility but also enables you to control when and how upgrades occur.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-dockerfile\">FROM ubuntu:20.04<\/code><\/pre>\n<h3>9. Analyze Image Size<\/h3>\n<p>Use tools like <code>dive<\/code> or <code>docker-squash<\/code> to analyze and visualize your <span class=\"glossaryai-tooltip glossary-term-739\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/image-layers\/\" target=\"_blank\">image layers<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Image layers are fundamental components in graphic design and editing software, allowing for the non-destructive manipulation of elements. Each layer can contain different images, effects, or adjustments, enabling precise control over composition and visual effects.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/image-layers\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This will help you identify any large layers or unnecessary files in your images that can be optimized.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-bash\">dive myimage:latest<\/code><\/pre>\n<h3>10. Use Docker Squash<\/h3>\n<p>Docker Squash is a technique that allows you to combine multiple layers into a single layer. This can significantly reduce the <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> size by eliminating redundant layers.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-bash\">docker build --squash -t myimage:latest .<\/code><\/pre>\n<h3>11. Use Scratch for Binaries<\/h3>\n<p>If your application doesn&#8217;t require a full OS, you can build your Docker <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> using <code>scratch<\/code>, which is an empty base <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This is particularly useful for statically compiled binaries.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre><code class=\"language-dockerfile\">FROM scratch\nCOPY myapp \/myapp\nCMD [\"\/myapp\"]<\/code><\/pre>\n<h3>12. Avoid Unused Packages<\/h3>\n<p>In a development environment, you may install packages for debugging or testing purposes. However, in production, only the necessary packages should be installed. Be sure to remove any unused packages from your final <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h3>13. Disable Cache for Non-Production Builds<\/h3>\n<p>While building images, Docker caches each layer. For non-production builds, you can disable caching to ensure that each layer is rebuilt, potentially leading to a cleaner and smaller <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<pre><code class=\"language-bash\">docker build --no-cache -t myimage:latest .<\/code><\/pre>\n<h3>14. Monitor and Maintain Regularly<\/h3>\n<p>Finally, <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> maintenance should not be a one-off <span class=\"glossaryai-tooltip glossary-term-683\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/task\/\" target=\"_blank\">task<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A task is a specific piece of work or duty assigned to an individual or system. It encompasses defined objectives, required resources, and expected outcomes, facilitating structured progress in various contexts.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/task\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. Regularly review and optimize your Docker images as part of your development lifecycle. Remove old images and unused layers to keep your environment clean.<\/p>\n<h2>Conclusion<\/h2>\n<p>Reducing the size of Docker images is crucial for enhancing performance, speeding up deployment, and conserving storage resources. By implementing these advanced techniques and best practices, developers can create efficient, lightweight Docker images. Understanding the underlying principles and maintaining a focus on optimization can lead to a more sustainable and manageable containerized environment.<\/p>\n<p>By continuously monitoring and refining your Docker images, you can ensure that your applications remain agile and scalable, aligning with the ever-evolving demands of modern software development. With a commitment to Docker best practices, you can enjoy the full benefits of containerization without the drawbacks of large, unwieldy images.<\/p>","protected":false},"excerpt":{"rendered":"<p>Para reducir Docker <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/image\/\" target=\"_blank\">imagen<\/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\/es\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> tama\u00f1o, utiliza builds multietapa, optimiza tu <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\">Un Dockerfile es un script que contiene una serie de instrucciones para automatizar la creaci\u00f3n de im\u00e1genes Docker. Especifica la imagen base, las dependencias de la aplicaci\u00f3n y la configuraci\u00f3n, facilitando el despliegue consistente en diferentes entornos.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> by minimizing layers, and remove unnecessary files. Consider using lighter base images like Alpine.<\/p>","protected":false},"author":1,"featured_media":296,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[],"class_list":["post-220","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 I reduce the size of Docker images? - 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\/es\/optimizacion-y-buenas-practicas\/para-reducir-el-tamano-de-las-imagenes-de-docker-puedes-seguir-estos-pasos1-utiliza-una-imagen-base-mas-pequena-en-lugar-de-usar-imagenes-base-grandes-como-ubuntu-o-centos-considera-usar-imagen\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How do I reduce the size of Docker images? - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"To reduce Docker image size, utilize multi-stage builds, optimize your Dockerfile by minimizing layers, and remove unnecessary files. Consider using lighter base images like Alpine.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/es\/optimizacion-y-buenas-practicas\/para-reducir-el-tamano-de-las-imagenes-de-docker-puedes-seguir-estos-pasos1-utiliza-una-imagen-base-mas-pequena-en-lugar-de-usar-imagenes-base-grandes-como-ubuntu-o-centos-considera-usar-imagen\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"article:published_time\" content=\"2024-07-21T11:45:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.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=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"dockerpros\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutos\" \/>\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-i-reduce-the-size-of-docker-images\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/\"},\"author\":{\"name\":\"dockerpros\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4\"},\"headline\":\"How do I reduce the size of Docker images?\",\"datePublished\":\"2024-07-21T11:45:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/\"},\"wordCount\":876,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dockerpros.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg\",\"articleSection\":[\"Optimization and Best Practices\"],\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/\",\"url\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/\",\"name\":\"How do I reduce the size of Docker images? - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg\",\"datePublished\":\"2024-07-21T11:45:27+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg\",\"width\":800,\"height\":600,\"caption\":\"how-do-i-reduce-the-size-of-docker-images-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dockerpros.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How do I reduce the size of Docker images?\"}]},{\"@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\":\"es\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dockerpros.com\/#organization\",\"name\":\"Dockerpros\",\"url\":\"https:\/\/dockerpros.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@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\":\"es\",\"@id\":\"https:\/\/dockerpros.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442\",\"caption\":\"dockerpros\"},\"sameAs\":[\"https:\/\/dockerpros.com\/\"],\"url\":\"https:\/\/dockerpros.com\/es\/author\/dockerpros\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reducir el tama\u00f1o de las im\u00e1genes de Docker es importante para optimizar el rendimiento y la eficiencia de tus contenedores. Aqu\u00ed tienes algunas estrategias para lograrlo:\n\n1. **Utiliza im\u00e1genes base m\u00e1s peque\u00f1as**: Opta por im\u00e1genes base minimalistas como Alpine Linux en lugar de im\u00e1genes m\u00e1s grandes como Ubuntu o Debian. Por ejemplo, en lugar de usar `FROM ubuntu:18.04`, puedes usar `FROM alpine:3.12`.\n\n2. **Elimina archivos innecesarios**: Durante el proceso de construcci\u00f3n, elimina archivos temporales, cach\u00e9s y dependencias que ya no sean necesarias. Puedes hacer esto utilizando comandos como `apt-get clean` o `rm -rf \/var\/lib\/apt\/lists\/*` en im\u00e1genes basadas en Debian.\n\n3. **Utiliza multi-stage builds**: Los multi-stage builds te permiten utilizar m\u00faltiples im\u00e1genes base en una sola Dockerfile. Puedes utilizar una imagen base para compilar tu aplicaci\u00f3n y luego copiar solo los archivos necesarios a una imagen base m\u00e1s peque\u00f1a. Por ejemplo:\n\n   ```dockerfile\n   FROM golang:1.15 AS builder\n   WORKDIR \/app\n   COPY . .\n   RUN go build -o main .\n\n   FROM alpine:3.12\n   WORKDIR \/app\n   COPY --from=builder \/app\/main .\n   CMD [\".\/main\"]\n   ```\n\n4. **Minimiza el n\u00famero de capas**: Cada instrucci\u00f3n en una Dockerfile crea una nueva capa en la imagen. Intenta combinar m\u00faltiples comandos en una sola instrucci\u00f3n RUN para reducir el n\u00famero de capas. Por ejemplo, en lugar de:\n\n   ```dockerfile\n   RUN apt-get update\n   RUN apt-get install -y package1\n   RUN apt-get install -y package2\n   ```\n\n   Puedes hacer:\n\n   ```dockerfile\n   RUN apt-get update &amp;&amp; apt-get install -y package1 package2\n   ```\n\n5. **Utiliza .dockerignore**: El archivo .dockerignore te permite excluir archivos y directorios espec\u00edficos del contexto de construcci\u00f3n. Esto evita que archivos innecesarios se copien a la imagen, reduciendo as\u00ed su tama\u00f1o.\n\n6. **Optimiza las dependencias**: Revisa las dependencias de tu aplicaci\u00f3n y elimina aquellas que no sean necesarias. Utiliza herramientas como `npm prune` para eliminar paquetes no utilizados en aplicaciones Node.js.\n\n7. **Utiliza im\u00e1genes oficiales**: Las im\u00e1genes oficiales de Docker suelen estar optimizadas y actualizadas regularmente. Utilizar im\u00e1genes oficiales en lugar de im\u00e1genes de terceros puede ayudar a reducir el tama\u00f1o de tus im\u00e1genes.\n\n8. **Comprueba el tama\u00f1o de las im\u00e1genes**: Utiliza comandos como `docker images` para verificar el tama\u00f1o de tus im\u00e1genes y identificar aquellas que son particularmente grandes. Esto te ayudar\u00e1 a enfocarte en las im\u00e1genes que m\u00e1s necesitan optimizaci\u00f3n.\n\nRecuerda que reducir el tama\u00f1o de las im\u00e1genes de Docker es un proceso iterativo. Experimenta con diferentes estrategias y herramientas para encontrar la combinaci\u00f3n que mejor se adapte a tus necesidades.","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\/es\/optimizacion-y-buenas-practicas\/para-reducir-el-tamano-de-las-imagenes-de-docker-puedes-seguir-estos-pasos1-utiliza-una-imagen-base-mas-pequena-en-lugar-de-usar-imagenes-base-grandes-como-ubuntu-o-centos-considera-usar-imagen\/","og_locale":"es_ES","og_type":"article","og_title":"How do I reduce the size of Docker images? - Dockerpros","og_description":"To reduce Docker image size, utilize multi-stage builds, optimize your Dockerfile by minimizing layers, and remove unnecessary files. Consider using lighter base images like Alpine.","og_url":"https:\/\/dockerpros.com\/es\/optimizacion-y-buenas-practicas\/para-reducir-el-tamano-de-las-imagenes-de-docker-puedes-seguir-estos-pasos1-utiliza-una-imagen-base-mas-pequena-en-lugar-de-usar-imagenes-base-grandes-como-ubuntu-o-centos-considera-usar-imagen\/","og_site_name":"Dockerpros","article_published_time":"2024-07-21T11:45:27+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg","type":"image\/jpeg"}],"author":"dockerpros","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"dockerpros","Tiempo de lectura":"5 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#article","isPartOf":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/"},"author":{"name":"dockerpros","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/a9b4c3d7f7a8e2b072e77d47b382a3a4"},"headline":"How do I reduce the size of Docker images?","datePublished":"2024-07-21T11:45:27+00:00","mainEntityOfPage":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/"},"wordCount":876,"commentCount":0,"publisher":{"@id":"https:\/\/dockerpros.com\/#organization"},"image":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg","articleSection":["Optimization and Best Practices"],"inLanguage":"es","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/","url":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/","name":"Reducir el tama\u00f1o de las im\u00e1genes de Docker es importante para optimizar el rendimiento y la eficiencia de tus contenedores. Aqu\u00ed tienes algunas estrategias para lograrlo:\n\n1. **Utiliza im\u00e1genes base m\u00e1s peque\u00f1as**: Opta por im\u00e1genes base minimalistas como Alpine Linux en lugar de im\u00e1genes m\u00e1s grandes como Ubuntu o Debian. Por ejemplo, en lugar de usar `FROM ubuntu:18.04`, puedes usar `FROM alpine:3.12`.\n\n2. **Elimina archivos innecesarios**: Durante el proceso de construcci\u00f3n, elimina archivos temporales, cach\u00e9s y dependencias que ya no sean necesarias. Puedes hacer esto utilizando comandos como `apt-get clean` o `rm -rf \/var\/lib\/apt\/lists\/*` en im\u00e1genes basadas en Debian.\n\n3. **Utiliza multi-stage builds**: Los multi-stage builds te permiten utilizar m\u00faltiples im\u00e1genes base en una sola Dockerfile. Puedes utilizar una imagen base para compilar tu aplicaci\u00f3n y luego copiar solo los archivos necesarios a una imagen base m\u00e1s peque\u00f1a. Por ejemplo:\n\n   ```dockerfile\n   FROM golang:1.15 AS builder\n   WORKDIR \/app\n   COPY . .\n   RUN go build -o main .\n\n   FROM alpine:3.12\n   WORKDIR \/app\n   COPY --from=builder \/app\/main .\n   CMD [\".\/main\"]\n   ```\n\n4. **Minimiza el n\u00famero de capas**: Cada instrucci\u00f3n en una Dockerfile crea una nueva capa en la imagen. Intenta combinar m\u00faltiples comandos en una sola instrucci\u00f3n RUN para reducir el n\u00famero de capas. Por ejemplo, en lugar de:\n\n   ```dockerfile\n   RUN apt-get update\n   RUN apt-get install -y package1\n   RUN apt-get install -y package2\n   ```\n\n   Puedes hacer:\n\n   ```dockerfile\n   RUN apt-get update &amp;&amp; apt-get install -y package1 package2\n   ```\n\n5. **Utiliza .dockerignore**: El archivo .dockerignore te permite excluir archivos y directorios espec\u00edficos del contexto de construcci\u00f3n. Esto evita que archivos innecesarios se copien a la imagen, reduciendo as\u00ed su tama\u00f1o.\n\n6. **Optimiza las dependencias**: Revisa las dependencias de tu aplicaci\u00f3n y elimina aquellas que no sean necesarias. Utiliza herramientas como `npm prune` para eliminar paquetes no utilizados en aplicaciones Node.js.\n\n7. **Utiliza im\u00e1genes oficiales**: Las im\u00e1genes oficiales de Docker suelen estar optimizadas y actualizadas regularmente. Utilizar im\u00e1genes oficiales en lugar de im\u00e1genes de terceros puede ayudar a reducir el tama\u00f1o de tus im\u00e1genes.\n\n8. **Comprueba el tama\u00f1o de las im\u00e1genes**: Utiliza comandos como `docker images` para verificar el tama\u00f1o de tus im\u00e1genes y identificar aquellas que son particularmente grandes. Esto te ayudar\u00e1 a enfocarte en las im\u00e1genes que m\u00e1s necesitan optimizaci\u00f3n.\n\nRecuerda que reducir el tama\u00f1o de las im\u00e1genes de Docker es un proceso iterativo. Experimenta con diferentes estrategias y herramientas para encontrar la combinaci\u00f3n que mejor se adapte a tus necesidades.","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg","datePublished":"2024-07-21T11:45:27+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/how-do-i-reduce-the-size-of-docker-images_220.jpg","width":800,"height":600,"caption":"how-do-i-reduce-the-size-of-docker-images-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/optimization-and-best-practices\/how-do-i-reduce-the-size-of-docker-images\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dockerpros.com\/"},{"@type":"ListItem","position":2,"name":"How do I reduce the size of Docker images?"}]},{"@type":"WebSite","@id":"https:\/\/dockerpros.com\/#website","url":"https:\/\/dockerpros.com\/","name":"Profesionales de Docker","description":"DockerPros \u2013 Tu centro definitivo de recursos Docker","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":"es"},{"@type":"Organization","@id":"https:\/\/dockerpros.com\/#organization","name":"Profesionales de Docker","url":"https:\/\/dockerpros.com\/","logo":{"@type":"ImageObject","inLanguage":"es","@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":"profesionales de Docker","image":{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/dockerpros.com\/#\/schema\/person\/image\/","url":"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442","contentUrl":"https:\/\/dockerpros.com\/wp-content\/litespeed\/avatar\/d13b9d4f101de1a7535b404e0c59affd.jpg?ver=1779972442","caption":"dockerpros"},"sameAs":["https:\/\/dockerpros.com\/"],"url":"https:\/\/dockerpros.com\/es\/author\/dockerpros\/"}]}},"_links":{"self":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":0,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/media\/296"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}