{"id":679,"date":"2024-07-22T20:37:51","date_gmt":"2024-07-22T20:37:51","guid":{"rendered":"https:\/\/dockerpros.com\/?post_type=glossary&#038;p=679"},"modified":"2024-07-23T14:46:06","modified_gmt":"2024-07-23T14:46:06","slug":"arg","status":"publish","type":"glossary","link":"https:\/\/dockerpros.com\/es\/wiki\/arg\/","title":{"rendered":"Argentina"},"content":{"rendered":"<h1>Understanding ARG in Docker: A Comprehensive Guide<\/h1>\n<p>In Docker, <code>ARG<\/code> is a directive used within Dockerfiles to define build-time variables that allow you to parameterize your builds. These variables can influence how 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> is constructed, enabling developers to create more flexible and reusable Docker images. Unlike environment variables (defined by the <code><span class=\"glossaryai-tooltip glossary-term-671\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\" target=\"_blank\">ENV<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">ENV, or Environmental Variables, are crucial in software development and system configuration. They store dynamic values that affect the execution environment, enabling flexible application behavior across different platforms.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code> instruction), which persist in the running <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, <code>ARG<\/code> values are only available during 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> build process, making them suitable for use cases such as specifying versions of software, toggling features, or managing configuration settings without hardcoding them into Dockerfiles.<\/p>\n<h2>The Role of ARG in Dockerfiles<\/h2>\n<p>The <code>ARG<\/code> instruction helps facilitate the separation of configuration from code. By employing <code>ARG<\/code>, developers can create images tailored to various environments (development, testing, production) without the need to maintain multiple Dockerfiles. This capability enhances maintainability and usability.<\/p>\n<p>For instance, consider a scenario where you need to build an application that links to different databases depending on the environment. Using <code>ARG<\/code>, you can define a variable for the database connection string that can be passed at build-time. This approach not only simplifies the build process but also minimizes the risk of errors associated with hardcoded values.<\/p>\n<h3>Syntax and Usage of ARG<\/h3>\n<p>The syntax for defining an <code>ARG<\/code> variable is straightforward:<\/p>\n<pre><code class=\"language-dockerfile\">ARG [=]<\/code><\/pre>\n<p>Here, <code>is the name of the variable, and<\/code> is an optional parameter that provides a fallback value if none is specified during the build process.<\/p>\n<h4>Example of Using ARG<\/h4>\n<pre><code class=\"language-dockerfile\">FROM ubuntu:20.04\n\nARG APP_VERSION=1.0\nARG BUILD_ENV=production\n\nRUN echo \"Building version: $APP_VERSION in $BUILD_ENV environment\"<\/code><\/pre>\n<p>In this example, we have defined two <code>ARG<\/code> variables: <code>APP_VERSION<\/code> and <code>BUILD_ENV<\/code>. If no values are provided at build-time, the 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> will default to <code>1.0<\/code> for <code>APP_VERSION<\/code> and <code>production<\/code> for <code>BUILD_ENV<\/code>.<\/p>\n<h3>Passing ARG Values at Build Time<\/h3>\n<p>When building a 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>, you can pass values to <code>ARG<\/code> using the <code>--build-arg<\/code> flag. Here\u2019s how you can do it:<\/p>\n<pre><code class=\"language-bash\">docker build --build-arg APP_VERSION=2.0 --build-arg BUILD_ENV=staging .<\/code><\/pre>\n<p>In this command, we override the default values, specifying that we want to build version <code>2.0<\/code> in a <code>staging<\/code> environment. The output of the <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> 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> will reflect these arguments.<\/p>\n<h3>Availability and Scope of ARG Variables<\/h3>\n<p>It\u2019s crucial to understand the scope of <code>ARG<\/code> variables. They are only available during 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> build process and cannot be accessed at runtime within the <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. This is different from <code><span class=\"glossaryai-tooltip glossary-term-671\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\" target=\"_blank\">ENV<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">ENV, or Environmental Variables, are crucial in software development and system configuration. They store dynamic values that affect the execution environment, enabling flexible application behavior across different platforms.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code> variables, which are available to both the build process and the running <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<p>For instance, if you try to access an <code>ARG<\/code> variable in a script that runs when the <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is started, you will find that it is undefined. Here\u2019s an example to illustrate this point:<\/p>\n<pre><code class=\"language-dockerfile\">FROM ubuntu:20.04\n\nARG APP_VERSION=1.0\n\nRUN echo \"Application version is $APP_VERSION\" &gt; \/app_version.txt\n\nCMD [\"cat\", \"\/app_version.txt\"]<\/code><\/pre>\n<p>If you build this 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> and <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> the <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, you will see <code>Application version is 1.0<\/code>. However, if you were to attempt to access <code>APP_VERSION<\/code> in a command executed by the <code><span class=\"glossaryai-tooltip glossary-term-670\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/cmd\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code>, it would yield nothing.<\/p>\n<h3>Best Practices for Using ARG<\/h3>\n<p>To make the most of <code>ARG<\/code> in your Dockerfiles, consider the following best practices:<\/p>\n<h4>1. Default Values<\/h4>\n<p>Always provide sensible default values for your <code>ARG<\/code> variables. This allows 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> to be built successfully even if no build-time arguments are specified.<\/p>\n<h4>2. Limit Scope<\/h4>\n<p>Keep the number of <code>ARG<\/code> directives to a minimum. Too many variables can lead to complexity and confusion. Only use them when necessary for configuration or customization.<\/p>\n<h4>3. Documentation<\/h4>\n<p>Document your <code>ARG<\/code> variables within 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>. Comments can help other developers understand the purpose of each variable, its default value, and how to override it during the build process.<\/p>\n<h4>4. Use ENV for Runtime Variables<\/h4>\n<p>Remember that <code>ARG<\/code> is not available at runtime. If you need configuration values at runtime, consider setting them as <code><span class=\"glossaryai-tooltip glossary-term-671\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\" target=\"_blank\">ENV<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">ENV, or Environmental Variables, are crucial in software development and system configuration. They store dynamic values that affect the execution environment, enabling flexible application behavior across different platforms.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code> variables after defining <code>ARG<\/code>:<\/p>\n<pre><code class=\"language-dockerfile\">FROM ubuntu:20.04\n\nARG APP_VERSION=1.0\nENV APP_VERSION=${APP_VERSION}\n\nRUN echo \"Application version is $APP_VERSION\"\n\nCMD [\"echo\", \"Running version $APP_VERSION\"]<\/code><\/pre>\n<p>In this setup, the <code>APP_VERSION<\/code> is available during both the build and runtime.<\/p>\n<h3>Use Cases for ARG<\/h3>\n<h4>1. Building Multiple Versions of Software<\/h4>\n<p>You can use <code>ARG<\/code> to build different versions of software depending on the build context. This is particularly useful for CI\/CD pipelines where you may want to build images for various versions automatically.<\/p>\n<pre><code class=\"language-dockerfile\">FROM <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>:14\n\nARG NODE_VERSION=14\n\n<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> npx node@${NODE_VERSION} -v<\/code><\/pre>\n<h4>2. Conditional Installation of Dependencies<\/h4>\n<p>You can conditionally install software package dependencies based on build-time arguments. This capability can help optimize 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 by including only necessary components:<\/p>\n<pre><code class=\"language-dockerfile\">FROM python:3.8\n\nARG INSTALL_DEPS=true\n\nRUN if [ \"$INSTALL_DEPS\" = \"true\" ]; then \n        pip install -r requirements.txt; \n    fi<\/code><\/pre>\n<h4>3. Multi-Stage Builds<\/h4>\n<p>In multi-stage builds, you can use <code>ARG<\/code> to pass parameters between different build stages:<\/p>\n<pre><code class=\"language-dockerfile\">FROM <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>:14 AS builder\n\nARG NODE_ENV=production\n<span class=\"glossaryai-tooltip glossary-term-671\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\" target=\"_blank\">ENV<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">ENV, or Environmental Variables, are crucial in software development and system configuration. They store dynamic values that affect the execution environment, enabling flexible application behavior across different platforms.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/env\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> NODE_ENV=${NODE_ENV}\n\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> . \/app\n<span class=\"glossaryai-tooltip glossary-term-675\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/workdir\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> \/app\n<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> npm install --only=${NODE_ENV}\n\nFROM nginx:alpine\n\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> --from=builder \/app\/build \/usr\/share\/nginx\/html<\/code><\/pre>\n<h3>Limitations of ARG<\/h3>\n<p>While <code>ARG<\/code> is a powerful feature, it comes with certain limitations:<\/p>\n<ol>\n<li><strong>Scope<\/strong>: As mentioned earlier, <code>ARG<\/code> variables cannot be accessed in the resulting <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>. Keep this in mind when designing your Dockerfiles.<\/li>\n<li><strong>Build-time Only<\/strong>: Since <code>ARG<\/code> is only available during the build phase, any dynamic configuration that you expect to change at runtime cannot utilize <code>ARG<\/code>.<\/li>\n<li><strong>No Runtime Persistence<\/strong>: Any value assigned to an <code>ARG<\/code> variable cannot persist beyond the build context, which limits its utility for dynamic behavior during <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> execution.<\/li>\n<\/ol>\n<h3>Advanced Topics: ARG in Docker Compose and CI\/CD Contexts<\/h3>\n<h4>Using ARG in Docker Compose<\/h4>\n<p><span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/wiki\/docker-compose\/\" target=\"_blank\">Docker Compose<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Docker Compose is a tool for defining and running multi-container Docker applications using a YAML file. It simplifies deployment, configuration, and orchestration of services, enhancing development efficiency.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/es\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> allows you to define build arguments directly in your <code>docker-compose.yml<\/code> file. Here\u2019s how you can do it:<\/p>\n<pre><code class=\"language-yaml\">version: \"3.8\"\nservices:\n  myapp:\n    build:\n      context: .\n      args:\n        APP_VERSION: \"2.0\"<\/code><\/pre>\n<p>In this setup, when you <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>docker-compose up<\/code>, the specified <code>APP_VERSION<\/code> will be passed to the build process.<\/p>\n<h4>ARG in CI\/CD Pipelines<\/h4>\n<p>In continuous integration and deployment pipelines, <code>ARG<\/code> becomes invaluable for building images dynamically based on the environment. You can configure your CI\/CD tool (e.g., Jenkins, GitLab CI, GitHub Actions) to pass different <code>ARG<\/code> values based on the branch, version tags, or even commit messages.<\/p>\n<p>For example, using GitHub Actions, you can define a job to 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>:<\/p>\n<pre><code class=\"language-yaml\">jobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Check out code\n        uses: actions\/checkout@v2\n\n      - name: Build Docker image\n        <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>: docker build --build-arg APP_VERSION=${{ github.sha }} .<\/code><\/pre>\n<p>In this case, each build will automatically use the commit SHA as the <code>APP_VERSION<\/code>, allowing you to track versions easily.<\/p>\n<h3>Conclusion<\/h3>\n<p>The <code>ARG<\/code> directive in Docker provides a powerful mechanism for parameterizing build processes, enabling developers to create more dynamic and flexible Docker images. By understanding its syntax, best practices, and appropriate use cases, you can leverage <code>ARG<\/code> to enhance your Dockerfiles and optimize your <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/es\/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\/es\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> workflows. While it has limitations, particularly in terms of scope and runtime availability, when used correctly, <code>ARG<\/code> can significantly improve your containerized application development experience. <\/p>\n<p>Incorporating <code>ARG<\/code> into your Docker strategy not only promotes cleaner and more maintainable code but also aligns with the growing need for adaptable and scalable software deployment practices. As you continue to explore Docker, consider how <code>ARG<\/code> can be an integral part of your image-building strategy and how it can contribute to more robust CI\/CD pipelines.<\/p>","protected":false},"excerpt":{"rendered":"<p>ARG es una directiva utilizada dentro de los Dockerfiles para definir variables de tiempo de construcci\u00f3n que permiten parametrizar tus construcciones. Estas variables pueden influir en c\u00f3mo se <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> se construye, lo que permite a los desarrolladores crear im\u00e1genes de Docker m\u00e1s flexibles y reutilizables.<\/p>","protected":false},"author":1,"featured_media":1472,"parent":0,"template":"","glossary-cat":[],"class_list":["post-679","glossary","type-glossary","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ARG - 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\/wiki\/arg\/\" \/>\n<meta property=\"og:locale\" content=\"es_ES\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ARG - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"ARG is a directive used within Dockerfiles to define build-time variables that allow you to parameterize your builds. These variables can influence how an image is constructed, enabling developers to create more flexible and reusable Docker images.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/es\/wiki\/arg\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-23T14:46:06+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"600\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Tiempo de lectura\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/arg\/\",\"url\":\"https:\/\/dockerpros.com\/wiki\/arg\/\",\"name\":\"ARG - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/arg\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/arg\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg\",\"datePublished\":\"2024-07-22T20:37:51+00:00\",\"dateModified\":\"2024-07-23T14:46:06+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/arg\/#breadcrumb\"},\"inLanguage\":\"es\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/wiki\/arg\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"es\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/arg\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg\",\"width\":800,\"height\":600,\"caption\":\"arg-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/arg\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dockerpros.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Glossary\",\"item\":\"https:\/\/dockerpros.com\/fr\/wiki\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"ARG\"}]},{\"@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\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ARG - Dockerpros","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dockerpros.com\/es\/wiki\/arg\/","og_locale":"es_ES","og_type":"article","og_title":"ARG - Dockerpros","og_description":"ARG is a directive used within Dockerfiles to define build-time variables that allow you to parameterize your builds. These variables can influence how an image is constructed, enabling developers to create more flexible and reusable Docker images.","og_url":"https:\/\/dockerpros.com\/es\/wiki\/arg\/","og_site_name":"Dockerpros","article_modified_time":"2024-07-23T14:46:06+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Tiempo de lectura":"6 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/wiki\/arg\/","url":"https:\/\/dockerpros.com\/wiki\/arg\/","name":"ARG - Dockerpros","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/wiki\/arg\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/wiki\/arg\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg","datePublished":"2024-07-22T20:37:51+00:00","dateModified":"2024-07-23T14:46:06+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/wiki\/arg\/#breadcrumb"},"inLanguage":"es","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/wiki\/arg\/"]}]},{"@type":"ImageObject","inLanguage":"es","@id":"https:\/\/dockerpros.com\/wiki\/arg\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/arg_679.jpg","width":800,"height":600,"caption":"arg-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/wiki\/arg\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dockerpros.com\/"},{"@type":"ListItem","position":2,"name":"Glossary","item":"https:\/\/dockerpros.com\/fr\/wiki\/"},{"@type":"ListItem","position":3,"name":"ARG"}]},{"@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\/"}}]}},"_links":{"self":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/glossary\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/glossary"}],"about":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/types\/glossary"}],"author":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":0,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/glossary\/679\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/media\/1472"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"glossary-cat","embeddable":true,"href":"https:\/\/dockerpros.com\/es\/wp-json\/wp\/v2\/glossary-cat?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}