{"id":1204,"date":"2024-07-22T20:45:44","date_gmt":"2024-07-22T20:45:44","guid":{"rendered":"https:\/\/dockerpros.com\/?post_type=glossary&#038;p=1204"},"modified":"2024-07-22T20:51:32","modified_gmt":"2024-07-22T20:51:32","slug":"docker-compose-variabili-dambiente","status":"publish","type":"glossary","link":"https:\/\/dockerpros.com\/it\/wiki\/docker-compose-environment-variables\/","title":{"rendered":"Variabili d'ambiente di Docker Compose"},"content":{"rendered":"<h1>Understanding Docker Compose Environment Variables<\/h1>\n<p><span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is a powerful tool that simplifies the management of multi-container Docker applications. At its core, it allows developers to define the services, networks, and volumes that their applications require in a single <code>docker-compose.yml<\/code> file. One of the most crucial features of <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> is the ability to utilize environment variables, which can enhance the flexibility, security, and reusability of your configuration. This article will delve into the various aspects of <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> environment variables, explaining their purpose, usage, and best practices.<\/p>\n<h2>What are Environment Variables?<\/h2>\n<p>Environment variables are dynamic values that can affect the way processes behave on a computer. They are frequently used to pass configuration information into applications, allowing developers to avoid hardcoding values directly into their code. In the context of Docker and <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, environment variables can be employed to define settings such as database connection strings, <span class=\"glossaryai-tooltip glossary-term-1249\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/api\/\" target=\"_blank\">API<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">An API, or Application Programming Interface, enables software applications to communicate and interact with each other. It defines protocols and tools for building software and facilitating integration.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/api\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> keys, and other sensitive information that should not be embedded in the source code.<\/p>\n<h2>Why Use Environment Variables with Docker Compose?<\/h2>\n<p>Using environment variables with <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> facilitates a more modular approach to configuration management. Here are several key benefits:<\/p>\n<ol>\n<li>\n<p><strong>Separation of Concerns<\/strong>: Environment variables allow you to separate your application&#8217;s code from its configuration. This means you can modify how your application runs without altering the underlying codebase.<\/p>\n<\/li>\n<li>\n<p><strong>Security<\/strong>: Storing sensitive information, such as passwords and <span class=\"glossaryai-tooltip glossary-term-1249\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/api\/\" target=\"_blank\">API<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">An API, or Application Programming Interface, enables software applications to communicate and interact with each other. It defines protocols and tools for building software and facilitating integration.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/api\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> keys, as environment variables keeps them out of your source code <span class=\"glossaryai-tooltip glossary-term-659\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/repository\/\" target=\"_blank\">repository<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A repository is a centralized location where data, code, or documents are stored, managed, and maintained. It facilitates version control, collaboration, and efficient resource sharing among users.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/repository\/\">More \u00bb<\/a><\/span><\/span><span class=\"gai-tooltip-video-wrapper\"><span class=\"gai-tooltip-video\" data-src=\"https:\/\/www.youtube.com\/embed\/_OXj8BGxNPY?rel=0&#038;modestbranding=1\"><\/span><\/span><\/span><\/span><\/span>, reducing the risk of accidental exposure.<\/p>\n<\/li>\n<li>\n<p><strong>Flexibility<\/strong>: You can easily change configuration settings depending on the environment (development, testing, production) without modifying your application code.<\/p>\n<\/li>\n<li>\n<p><strong>Simplicity<\/strong>: Managing settings through environment variables can simplify the deployment and <span class=\"glossaryai-tooltip glossary-term-657\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/orchestration\/\" target=\"_blank\">orchestration<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Orchestration refers to the automated management and coordination of complex systems and services. It optimizes processes by integrating various components, ensuring efficient operation and resource utilization.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/orchestration\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> of multi-container applications.<\/p>\n<\/li>\n<\/ol>\n<h2>Defining Environment Variables in Docker Compose<\/h2>\n<p><span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> allows you to define environment variables in multiple ways. Below are the most common methods:<\/p>\n<h3>1. Using the Environment Section<\/h3>\n<p>The simplest way to define environment variables is by using the <code>environment<\/code> key in your <code>docker-compose.yml<\/code> file. <\/p>\n<pre><code class=\"language-yaml\">version: '3.8'\n\nservices:\n  web:\n    <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>: my-web-app\n    environment:\n      - NODE_ENV=production\n      - API_KEY=your_api_key_here<\/code><\/pre>\n<p>In this example, two environment variables, <code>NODE_ENV<\/code> and <code>API_KEY<\/code>, are defined for the <code>web<\/code> <span class=\"glossaryai-tooltip glossary-term-681\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/service\/\" target=\"_blank\">service<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Service refers to the act of providing assistance or support to fulfill specific needs or requirements. In various domains, it encompasses customer service, technical support, and professional services, emphasizing efficiency and user satisfaction.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/service\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h3>2. Using an <code>.env<\/code> File<\/h3>\n<p>A more organized approach for managing environment variables is to use an <code>.env<\/code> file. <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> automatically reads this file and loads the key-value pairs as environment variables.<\/p>\n<p>Create a file named <code>.env<\/code>:<\/p>\n<pre><code class=\"language-dotenv\">NODE_ENV=production\nAPI_KEY=your_api_key_here<\/code><\/pre>\n<p>Then, reference the variables in your <code>docker-compose.yml<\/code>:<\/p>\n<pre><code class=\"language-yaml\">version: '3.8'\n\nservices:\n  web:\n    <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>: my-web-app\n    environment:\n      - NODE_ENV=${NODE_ENV}\n      - API_KEY=${API_KEY}<\/code><\/pre>\n<p>This method enhances readability and maintainability since you can manage environment variables in a dedicated file.<\/p>\n<h3>3. Using Shell Environment Variables<\/h3>\n<p>You can also pass environment variables from your shell directly to the <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> command:<\/p>\n<pre><code class=\"language-bash\">export NODE_ENV=production\nexport API_KEY=your_api_key_here\ndocker-compose up<\/code><\/pre>\n<p>In this case, the variables are referenced in the <code>docker-compose.yml<\/code> as you would normally.<\/p>\n<h3>4. Using Variable Substitution<\/h3>\n<p><span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> supports variable substitution in the <code>docker-compose.yml<\/code> file. Variables can be defined in the <code>.env<\/code> file or directly in the shell, and you can use them throughout the file.<\/p>\n<pre><code class=\"language-yaml\">version: '3.8'\n\nservices:\n  web:\n    <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>: my-web-app\n    environment:\n      - NODE_ENV=${NODE_ENV:-development}\n      - API_KEY=${API_KEY}<\/code><\/pre>\n<p>In this example, if <code>NODE_ENV<\/code> is not set, it will default to <code>development<\/code>.<\/p>\n<h2>Best Practices for Using Environment Variables<\/h2>\n<p>While using environment variables can greatly enhance your <span class=\"glossaryai-tooltip glossary-term-1285\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/docker-compose-configurations\/\" target=\"_blank\">Docker Compose configurations<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Docker Compose configurations streamline multi-container application deployment by defining services, networks, and volumes in a single YAML file. This modular approach enhances scalability and management.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/docker-compose-configurations\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, there are several best practices to keep in mind:<\/p>\n<h3>1. Avoid Hardcoding Sensitive Information<\/h3>\n<p>Keep sensitive information out of your <code>docker-compose.yml<\/code> file. Use <code>.env<\/code> files or <span class=\"glossaryai-tooltip glossary-term-687\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\" target=\"_blank\">secret<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">The concept of \"secret\" encompasses information withheld from others, often for reasons of privacy, security, or confidentiality. Understanding its implications is crucial in fields such as data protection and communication theory.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> management solutions like AWS Secrets Manager, HashiCorp Vault, or Docker Secrets to manage sensitive data securely.<\/p>\n<h3>2. Use Descriptive Names<\/h3>\n<p>Choose clear and descriptive names for your environment variables. This makes your configuration more understandable and easier to maintain.<\/p>\n<h3>3. Document Your Environment Variables<\/h3>\n<p>Include documentation that outlines what each environment variable does, especially if you are working in a team. This can be done within the <code>.env<\/code> file as comments or in separate documentation.<\/p>\n<h3>4. Use Default Values Wisely<\/h3>\n<p>When using variable substitution, consider setting default values to ensure your application has sensible fallbacks if environment variables are not provided.<\/p>\n<h3>5. Keep Your <code>.env<\/code> Files Secure<\/h3>\n<p>Since <code>.env<\/code> files can contain sensitive information, ensure they are not included in your version control system. Use a <code>.gitignore<\/code> file to exclude them from your Git <span class=\"glossaryai-tooltip glossary-term-659\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/repository\/\" target=\"_blank\">repository<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">A repository is a centralized location where data, code, or documents are stored, managed, and maintained. It facilitates version control, collaboration, and efficient resource sharing among users.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/repository\/\">More \u00bb<\/a><\/span><\/span><span class=\"gai-tooltip-video-wrapper\"><span class=\"gai-tooltip-video\" data-src=\"https:\/\/www.youtube.com\/embed\/_OXj8BGxNPY?rel=0&#038;modestbranding=1\"><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h2>Advanced Usage of Environment Variables<\/h2>\n<h3>1. Combining Environment Variables with Docker Secrets<\/h3>\n<p>For enhanced security, especially in production environments, it is advisable to combine environment variables with Docker Secrets. Docker Secrets are designed to securely store and manage sensitive data, such as passwords and <span class=\"glossaryai-tooltip glossary-term-1249\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/api\/\" target=\"_blank\">API<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">An API, or Application Programming Interface, enables software applications to communicate and interact with each other. It defines protocols and tools for building software and facilitating integration.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/api\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> keys.<\/p>\n<p>To use Docker Secrets, first create a <span class=\"glossaryai-tooltip glossary-term-687\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\" target=\"_blank\">secret<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">The concept of \"secret\" encompasses information withheld from others, often for reasons of privacy, security, or confidentiality. Understanding its implications is crucial in fields such as data protection and communication theory.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>:<\/p>\n<pre><code class=\"language-bash\">echo \"your_api_key_here\" | docker <span class=\"glossaryai-tooltip glossary-term-687\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\" target=\"_blank\">secret<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">The concept of \"secret\" encompasses information withheld from others, often for reasons of privacy, security, or confidentiality. Understanding its implications is crucial in fields such as data protection and communication theory.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> create api_key -<\/code><\/pre>\n<p>Then, reference the <span class=\"glossaryai-tooltip glossary-term-687\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\" target=\"_blank\">secret<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">The concept of \"secret\" encompasses information withheld from others, often for reasons of privacy, security, or confidentiality. Understanding its implications is crucial in fields such as data protection and communication theory.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> in your <code>docker-compose.yml<\/code>:<\/p>\n<pre><code class=\"language-yaml\">version: '3.8'\n\nservices:\n  web:\n    <span class=\"glossaryai-tooltip glossary-term-651\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/image\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>: my-web-app\n    secrets:\n      - api_key\n\nsecrets:\n  api_key:\n    external: true<\/code><\/pre>\n<p>Inside your <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, the <span class=\"glossaryai-tooltip glossary-term-687\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\" target=\"_blank\">secret<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">The concept of \"secret\" encompasses information withheld from others, often for reasons of privacy, security, or confidentiality. Understanding its implications is crucial in fields such as data protection and communication theory.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/secret\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> will be available in the <code>\/run\/secrets\/api_key<\/code> file.<\/p>\n<h3>2. Environment Variables for Multi-Stage Builds<\/h3>\n<p>When using Docker multi-stage builds, environment variables can also be utilized to control the build context. Here&#8217;s an example:<\/p>\n<pre><code class=\"language-dockerfile\"># syntax=docker\/dockerfile:1\n\nFROM <span class=\"glossaryai-tooltip glossary-term-684\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/node\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>:14 AS build\n\n<span class=\"glossaryai-tooltip glossary-term-679\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/arg\/\" target=\"_blank\">ARG<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">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.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/arg\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> NODE_ENV\n<span class=\"glossaryai-tooltip glossary-term-671\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/env\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> NODE_ENV=${NODE_ENV}\n\n<span class=\"glossaryai-tooltip glossary-term-675\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/workdir\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> \/app\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> . .\n\n<span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> npm install\n<span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> npm <span class=\"glossaryai-tooltip glossary-term-672\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/run\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> build\n\nFROM nginx:alpine\n<span class=\"glossaryai-tooltip glossary-term-673\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/copy\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> --from=build \/app\/build \/usr\/share\/nginx\/html<\/code><\/pre>\n<p>In this case, you can specify the <code>NODE_ENV<\/code> variable at build time:<\/p>\n<pre><code class=\"language-bash\">docker build --build-arg NODE_ENV=production -t my-web-app .<\/code><\/pre>\n<h3>3. Configuration Management Tools<\/h3>\n<p>For more complex applications, consider using configuration management tools like Docker Configs or using <span class=\"glossaryai-tooltip glossary-term-657\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/orchestration\/\" target=\"_blank\">orchestration<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Orchestration refers to the automated management and coordination of complex systems and services. It optimizes processes by integrating various components, ensuring efficient operation and resource utilization.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/orchestration\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> tools like <span class=\"glossaryai-tooltip glossary-term-656\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/kubernetes\/\" target=\"_blank\">Kubernetes<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications, enhancing resource efficiency and resilience.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/kubernetes\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> ConfigMaps and Secrets. These tools allow you to manage environment variables across multiple deployments seamlessly.<\/p>\n<h2>Debugging Environment Variables<\/h2>\n<p>Debugging environment variables in <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> can be challenging. Here are some strategies:<\/p>\n<h3>1. Inspecting Running Containers<\/h3>\n<p>You can inspect running containers to view their environment variables:<\/p>\n<pre><code class=\"language-bash\">docker exec -it  <span class=\"glossaryai-tooltip glossary-term-671\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/env\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code><\/pre>\n<p>This command will list all the environment variables defined within the specified <span class=\"glossaryai-tooltip glossary-term-650\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/container\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>.<\/p>\n<h3>2. Using <code>docker-compose <span class=\"glossaryai-tooltip glossary-term-688\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/config\/\" target=\"_blank\">config<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Config refers to configuration settings that determine how software or hardware operates. It encompasses parameters that influence performance, security, and functionality, enabling tailored user experiences.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/config\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code><\/h3>\n<p>This command shows the final configuration of your Compose file after resolving environment variables:<\/p>\n<pre><code class=\"language-bash\">docker-compose <span class=\"glossaryai-tooltip glossary-term-688\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/config\/\" target=\"_blank\">config<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">Config refers to configuration settings that determine how software or hardware operates. It encompasses parameters that influence performance, security, and functionality, enabling tailored user experiences.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/config\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span><\/code><\/pre>\n<p>It is an excellent way to confirm that your variables are being loaded correctly.<\/p>\n<h3>3. Logging Environment Variables<\/h3>\n<p>You can <span class=\"glossaryai-tooltip glossary-term-674\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/wiki\/add\/\" target=\"_blank\">add<\/a><\/span><span class=\"gai-content-hidden glossaryai-tooltip-content\"><span class=\"gai-tooltip-body\"><span class=\"glossaryai-tooltip-text\">The ADD instruction in Docker is a command used in Dockerfiles to copy files and directories from a host machine into a Docker image during the build process. It not only facilitates the transfer of local files but also provides additional functionality, such as automatically extracting compressed files and fetching remote files via HTTP or HTTPS.<span class=\"glossaryai-more-link\"> <a href=\"https:\/\/dockerpros.com\/it\/wiki\/add\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> a temporary logging command to your <span class=\"glossaryai-tooltip glossary-term-652\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/dockerfile\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> to print out environment variables during the build or startup process:<\/p>\n<pre><code class=\"language-dockerfile\">CMD [\"sh\", \"-c\", \"env &amp;&amp; exec your_app\"]<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>Environment variables in <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> play a pivotal role in configuring applications in a flexible and secure manner. By understanding how to define, manage, and utilize these variables effectively, developers can ensure that their multi-container applications are both robust and adaptable to various environments. By following best practices and leveraging advanced techniques such as Docker Secrets, you can enhance the security and maintainability of your Docker deployments.<\/p>\n<p>As you continue to work with <span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span>, consider how environment variables can streamline your workflow and improve your application&#8217;s architecture. With careful planning and execution, environment variables can significantly contribute to the overall efficiency and security of your Docker-based applications.<\/p>","protected":false},"excerpt":{"rendered":"<p><span class=\"glossaryai-tooltip glossary-term-654\"><span class=\"glossaryai-link\"><a href=\"https:\/\/dockerpros.com\/it\/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\/it\/wiki\/docker-compose\/\">More \u00bb<\/a><\/span><\/span><\/span><\/span><\/span> consente l'utilizzo di variabili d'ambiente per configurare i servizi in modo dinamico. Definendo le variabili in un file `.env` o direttamente in `docker-compose.yml`, gli utenti possono personalizzare le impostazioni senza codificare i valori in modo rigido, migliorando la portabilit\u00e0 e la sicurezza.<\/p>","protected":false},"author":1,"featured_media":1725,"parent":0,"template":"","glossary-cat":[],"class_list":["post-1204","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>Docker Compose Environment Variables - 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\/it\/wiki\/docker-compose-variabili-dambiente\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Docker Compose Environment Variables - Dockerpros\" \/>\n<meta property=\"og:description\" content=\"Docker Compose allows the use of environment variables to configure services dynamically. By defining variables in a `.env` file or directly in `docker-compose.yml`, users can customize settings without hardcoding values, enhancing portability and security.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dockerpros.com\/it\/wiki\/docker-compose-variabili-dambiente\/\" \/>\n<meta property=\"og:site_name\" content=\"Dockerpros\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-22T20:51:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.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=\"Tempo di lettura stimato\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/\",\"url\":\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/\",\"name\":\"Docker Compose Environment Variables - Dockerpros\",\"isPartOf\":{\"@id\":\"https:\/\/dockerpros.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.jpg\",\"datePublished\":\"2024-07-22T20:45:44+00:00\",\"dateModified\":\"2024-07-22T20:51:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#primaryimage\",\"url\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.jpg\",\"contentUrl\":\"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.jpg\",\"width\":800,\"height\":600,\"caption\":\"docker-compose-environment-variables-2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#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\":\"Docker Compose Environment Variables\"}]},{\"@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\":\"it-IT\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dockerpros.com\/#organization\",\"name\":\"Dockerpros\",\"url\":\"https:\/\/dockerpros.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@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":"Variabili d'Ambiente di Docker Compose - 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\/it\/wiki\/docker-compose-variabili-dambiente\/","og_locale":"it_IT","og_type":"article","og_title":"Docker Compose Environment Variables - Dockerpros","og_description":"Docker Compose allows the use of environment variables to configure services dynamically. By defining variables in a `.env` file or directly in `docker-compose.yml`, users can customize settings without hardcoding values, enhancing portability and security.","og_url":"https:\/\/dockerpros.com\/it\/wiki\/docker-compose-variabili-dambiente\/","og_site_name":"Dockerpros","article_modified_time":"2024-07-22T20:51:32+00:00","og_image":[{"width":800,"height":600,"url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Tempo di lettura stimato":"6 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/","url":"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/","name":"Variabili d'Ambiente di Docker Compose - Dockerpros","isPartOf":{"@id":"https:\/\/dockerpros.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#primaryimage"},"image":{"@id":"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#primaryimage"},"thumbnailUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.jpg","datePublished":"2024-07-22T20:45:44+00:00","dateModified":"2024-07-22T20:51:32+00:00","breadcrumb":{"@id":"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/"]}]},{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#primaryimage","url":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.jpg","contentUrl":"https:\/\/dockerpros.com\/wp-content\/uploads\/2024\/07\/docker-compose-environment-variables_1204.jpg","width":800,"height":600,"caption":"docker-compose-environment-variables-2"},{"@type":"BreadcrumbList","@id":"https:\/\/dockerpros.com\/wiki\/docker-compose-environment-variables\/#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":"Docker Compose Environment Variables"}]},{"@type":"WebSite","@id":"https:\/\/dockerpros.com\/#website","url":"https:\/\/dockerpros.com\/","name":"Esperti Docker","description":"DockerPros \u2013 Il tuo punto di riferimento definitivo per 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":"it-IT"},{"@type":"Organization","@id":"https:\/\/dockerpros.com\/#organization","name":"Esperti Docker","url":"https:\/\/dockerpros.com\/","logo":{"@type":"ImageObject","inLanguage":"it-IT","@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\/it\/wp-json\/wp\/v2\/glossary\/1204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dockerpros.com\/it\/wp-json\/wp\/v2\/glossary"}],"about":[{"href":"https:\/\/dockerpros.com\/it\/wp-json\/wp\/v2\/types\/glossary"}],"author":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/it\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":0,"href":"https:\/\/dockerpros.com\/it\/wp-json\/wp\/v2\/glossary\/1204\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dockerpros.com\/it\/wp-json\/wp\/v2\/media\/1725"}],"wp:attachment":[{"href":"https:\/\/dockerpros.com\/it\/wp-json\/wp\/v2\/media?parent=1204"}],"wp:term":[{"taxonomy":"glossary-cat","embeddable":true,"href":"https:\/\/dockerpros.com\/it\/wp-json\/wp\/v2\/glossary-cat?post=1204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}