{"id":53812,"date":"2025-09-14T17:11:42","date_gmt":"2025-09-14T07:11:42","guid":{"rendered":"https:\/\/www.cloudproinc.com.au\/?p=53812"},"modified":"2025-09-14T17:11:45","modified_gmt":"2025-09-14T07:11:45","slug":"mastering-docker-environment-variables-with-docker","status":"publish","type":"post","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/","title":{"rendered":"Mastering Docker environment variables with Docker"},"content":{"rendered":"\n<p>In this blog post Mastering Docker environment variables with Docker Compose we will walk through how to use environment variables confidently across Docker and Docker Compose, and how to avoid the common gotchas.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Environment variables are a simple, time-tested way to keep configuration outside your code. With containers, they become even more useful: the same image can run in multiple environments by swapping values at runtime. In this guide, we\u2019ll start with the big picture and then show practical steps you can copy into your projects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-high-level-overview\">High-level overview<\/h2>\n\n\n\n<p><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/category\/docker\/\">Docker <\/a>images are built once, then run many times. Build-time settings shape how an image is produced. Runtime settings configure how a container behaves when it starts. Environment variables bridge both worlds:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>At build time<\/strong>, <code>ARG<\/code> values let you parameterise the build without baking sensitive data into the image.<\/li>\n\n\n\n<li><strong>At runtime<\/strong>, <code>ENV<\/code> and Compose\u2019s <code>environment<\/code> entries set application config inside the container.<\/li>\n\n\n\n<li><strong>Compose<\/strong> adds a <code>.env<\/code> file and variable substitution to keep your YAML tidy and DRY across machines.<\/li>\n<\/ul>\n\n\n\n<p>The result: one codebase and one set of Dockerfiles can support dev, test, and production with minimal drift.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-technology-behind-it\">The technology behind it<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-dockerfile-arg-vs-env\">Dockerfile: ARG vs ENV<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ARG<\/code> exists only during <code>docker build<\/code>. It\u2019s not present at runtime unless you copy it into an <code>ENV<\/code> or your app.<\/li>\n\n\n\n<li><code>ENV<\/code> persists in the built image and becomes part of every container spawned from it.<\/li>\n<\/ul>\n\n\n\n<p>Use <code>ARG<\/code> for build toggles (e.g., base image tag, package registry), and <code>ENV<\/code> for runtime defaults (e.g., <code>NODE_ENV=production<\/code>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-docker-compose-env-environment-env-file\">Docker Compose: .env, environment, env_file<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>.env<\/code><\/strong> in the Compose project directory provides values for variable substitution inside the YAML (e.g., <code>${IMAGE_TAG}<\/code>). These are parsed at <em>compose-file load time<\/em>.<\/li>\n\n\n\n<li><strong><code>environment<\/code><\/strong> sets variables inside the running container.<\/li>\n\n\n\n<li><strong><code>env_file<\/code><\/strong> loads key-value pairs and injects them into the container environment (similar to <code>--env-file<\/code> with <code>docker run<\/code>).<\/li>\n<\/ul>\n\n\n\n<p>Key point: variables in <code>.env<\/code> do not automatically become container environment variables unless you reference them in <code>environment<\/code> or include them via <code>env_file<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-quick-start-in-three-files\">Quick start in three files<\/h2>\n\n\n\n<p>Here\u2019s a minimal but realistic setup. It shows build-time args, runtime env, and Compose substitution.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-env\">1) .env<\/h3>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d7205ea85218f34bee318d41462a7331\"><code>APP_NAME=payments-api\nAPP_PORT=8080\nIMAGE_TAG=1.4.2\nDB_HOST=db\nDB_USER=app\n# Do not commit real secrets to .env\nDB_PASSWORD=change_me\nDEBUG=false\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-dockerfile\">2) Dockerfile<\/h3>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-ca6efb2d06b3ff9c204aec253b80cf8e\"><code># syntax=docker\/dockerfile:1\nARG BASE_IMAGE=node:20-alpine\nFROM ${BASE_IMAGE} as runtime\n\n# Build args are available only during build\nARG APP_NAME\nARG BUILD_DATE\n\n# Runtime defaults (can be overridden at container start)\nENV NODE_ENV=production \\\n    APP_NAME=${APP_NAME:-app}\n\nWORKDIR \/app\nCOPY package*.json .\/\nRUN npm ci --omit=dev\nCOPY . .\n\n# Example of using ARG during build steps\nRUN echo \"Building ${APP_NAME:-app} on ${BUILD_DATE:-unknown}\" &amp;&amp; \\\n    npm run build\n\nCMD &#91;\"node\", \"dist\/server.js\"]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-docker-compose-yml\">3) docker-compose.yml<\/h3>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-ed82d72574a436b323b9d360d23ad0bf\"><code>services:\n  api:\n    build:\n      context: .\n      dockerfile: Dockerfile\n      args:\n        APP_NAME: ${APP_NAME}\n        BASE_IMAGE: node:20-alpine\n        BUILD_DATE: ${BUILD_DATE:-now}\n    image: cloudproinc\/${APP_NAME}:${IMAGE_TAG}\n    ports:\n      - \"${APP_PORT}:8080\"\n    environment:\n      NODE_ENV: production\n      DB_HOST: ${DB_HOST}\n      DB_USER: ${DB_USER}\n      # Illustrative only; prefer secrets for real passwords\n      DB_PASSWORD: ${DB_PASSWORD}\n      DEBUG: ${DEBUG:-false}\n    # Alternatively, inject many variables at once\n    # env_file:\n    #   - .\/.env\n\n  db:\n    image: postgres:16\n    environment:\n      POSTGRES_USER: ${DB_USER}\n      POSTGRES_PASSWORD: ${DB_PASSWORD}\n      POSTGRES_DB: ${APP_NAME}\n    volumes:\n      - pgdata:\/var\/lib\/postgresql\/data\n\nvolumes:\n  pgdata:\n<\/code><\/pre>\n\n\n\n<p>Run it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose up --build -d\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-compose-variable-substitution-works\">How Compose variable substitution works<\/h2>\n\n\n\n<p>Compose supports shell-style interpolation inside the YAML. Common patterns:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>${VAR}<\/code> \u2013 use value from <code>.env<\/code> or your shell\u2019s environment.<\/li>\n\n\n\n<li><code>${VAR:-default}<\/code> \u2013 use <code>default<\/code> if <code>VAR<\/code> is unset or empty.<\/li>\n\n\n\n<li><code>${VAR?error}<\/code> \u2013 fail with a message if <code>VAR<\/code> is missing.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  api:\n    image: cloudproinc\/${APP_NAME}:${IMAGE_TAG:-latest}\n    environment:\n      LOG_LEVEL: ${LOG_LEVEL:-info}\n      REQUIRED_TOKEN: ${REQUIRED_TOKEN?Set REQUIRED_TOKEN in your environment}\n<\/code><\/pre>\n\n\n\n<p>Remember: these substitutions happen when Compose parses the YAML, not at container runtime. If a value looks wrong, render the final config to inspect it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose config\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-precedence-and-scope\">Precedence and scope<\/h2>\n\n\n\n<p>Where does a container\u2019s final environment variable value come from? Highest to lowest precedence:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Explicit values passed at runtime via <code>docker run -e<\/code> or <code>--env-file<\/code> (when not using Compose).<\/li>\n\n\n\n<li>Compose <code>environment<\/code> entries.<\/li>\n\n\n\n<li>Compose <code>env_file<\/code> entries.<\/li>\n\n\n\n<li><code>ENV<\/code> defaults in the Dockerfile image.<\/li>\n<\/ul>\n\n\n\n<p>Separately, for <em>Compose file interpolation<\/em>, values come from (in order):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Environment of the <em>Compose process<\/em> (your shell).<\/li>\n\n\n\n<li>The <code>.env<\/code> file located in the Compose project directory.<\/li>\n\n\n\n<li>Defaults like <code>${VAR:-...}<\/code> inside the YAML.<\/li>\n<\/ul>\n\n\n\n<p>These two ladders are often confused. Interpolation fills the YAML. Runtime precedence decides what\u2019s inside the container.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-using-docker-run-directly\">Using docker run directly<\/h2>\n\n\n\n<p>If you\u2019re not using Compose, you can pass vars inline or via files:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-c2256ba7404ea22ae8f21b4d663c69f4\"><code># Inline values\ndocker run -e APP_PORT=8080 -e DEBUG=false my-image\n\n# From a file (KEY=VALUE per line)\ndocker run --env-file .env my-image<\/code><\/pre>\n\n\n\n<p>Check what the container sees:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-8edc292c645fe57aab627545bc9b275c\"><code>docker run --rm -e FOO=bar alpine:3 env | sort\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-handling-secrets-safely\">Handling secrets safely<\/h2>\n\n\n\n<p>Environment variables are convenient but not ideal for secrets. They may appear in <code>docker inspect<\/code>, crash logs, or process listings inside the container. Prefer:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Docker secrets<\/strong> (Swarm) or <strong>Compose secrets<\/strong> with files mounted at runtime.<\/li>\n\n\n\n<li>External secret managers (cloud KMS, Vault) with SDKs or sidecars.<\/li>\n<\/ul>\n\n\n\n<p>Example using file-based secret with Compose:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-876933b3be58033fcd0b32edf5cb1117\"><code>services:\n  api:\n    image: cloudproinc\/${APP_NAME}:${IMAGE_TAG}\n    environment:\n      DB_PASSWORD_FILE: \/run\/secrets\/db_password\n    secrets:\n      - db_password\n\nsecrets:\n  db_password:\n    file: .\/secrets\/db_password.txt\n<\/code><\/pre>\n\n\n\n<p>Your app reads the file at <code>\/run\/secrets\/db_password<\/code> instead of a plain env var.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-debugging-and-verification\">Debugging and verification<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Render the final Compose config<\/strong>: <code>docker compose config<\/code><\/li>\n\n\n\n<li><strong>Inspect a container<\/strong>: <code>docker inspect &lt;container><\/code> shows <code>Config.Env<\/code><\/li>\n\n\n\n<li><strong>Print inside the container<\/strong>: <code>docker exec &lt;container> env | sort<\/code><\/li>\n\n\n\n<li><strong>Recreate with new values<\/strong>: <code>docker compose up -d --build --force-recreate<\/code><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\"><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-production-tips\">Production tips<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep a minimal, documented <code>.env.example<\/code> checked into source control; never commit real secrets.<\/li>\n\n\n\n<li>Separate concerns: build once with <code>ARG<\/code>, configure many times with runtime env.<\/li>\n\n\n\n<li>Pin base images and package versions via <code>ARG<\/code> for reproducibility.<\/li>\n\n\n\n<li>Use Compose profiles or separate override files to switch stacks or turn features on\/off.<\/li>\n\n\n\n<li>Centralise environment management in your CI\/CD and pass values to Compose at deploy time.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-putting-it-all-together\">Putting it all together<\/h2>\n\n\n\n<p>Environment variables give you a clean separation between code and configuration. Docker provides the mechanics (<code>ARG<\/code>, <code>ENV<\/code>), while Compose adds ergonomics (<code>.env<\/code>, interpolation, <code>env_file<\/code>). With a small amount of structure\u2014defaults in the Dockerfile, environment blocks in Compose, and secrets out of env\u2014you get portable builds, predictable runtime behavior, and a safer path to production.<\/p>\n\n\n\n<p>Start with the three-file quick start above, verify with <code>docker compose config<\/code>, and evolve from there. You\u2019ll quickly find that managing configuration this way scales smoothly from a developer laptop to your production cluster.<\/p>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links yoast-seo-related-links\">\n<li><a href=\"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/11\/the-benefits-of-using-docker-compose-for-teams-and-projects\/\">The Benefits of Using Docker Compose for Teams and Projects<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/04\/18\/adding-environment-variables-to-visual-studio-2022\/\">Adding Environment Variables to Visual Studio 2022<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/08\/08\/use-azure-managed-identity-with-azure-automation-powershell\/\">Use Azure Managed Identity with Azure Automation PowerShell<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/07\/29\/counting-tokens-using-the-openai-python-sdk\/\">Counting Tokens Using the OpenAI Python SDK<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/08\/25\/run-neo4j-with-docker-inside-github-codespaces\/\">Run Neo4j with Docker inside GitHub Codespaces<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to manage configuration with Docker and Compose using environment variables, from build-time and runtime to .env files, secrets, precedence, and pitfalls. Practical steps and examples included.<\/p>\n","protected":false},"author":1,"featured_media":53813,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"Mastering Docker environment variables with Docker","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Unlock the secrets of Docker with mastering Docker environment variables. Learn to use them confidently with Docker Compose.","_yoast_wpseo_opengraph-title":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_twitter-title":"","_yoast_wpseo_twitter-description":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,70],"tags":[],"class_list":["post-53812","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-docker"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Mastering Docker environment variables with Docker - CPI Consulting<\/title>\n<meta name=\"description\" content=\"Unlock the secrets of Docker with mastering Docker environment variables. Learn to use them confidently with Docker Compose.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mastering Docker environment variables with Docker\" \/>\n<meta property=\"og:description\" content=\"Unlock the secrets of Docker with mastering Docker environment variables. Learn to use them confidently with Docker Compose.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/\" \/>\n<meta property=\"og:site_name\" content=\"CPI Consulting\" \/>\n<meta property=\"article:published_time\" content=\"2025-09-14T07:11:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-14T07:11:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudproinc.azurewebsites.net\/wp-content\/uploads\/2025\/09\/mastering-docker-environment-variables-with-docker-compose-today.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CPI Staff\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CPI Staff\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/\"},\"author\":{\"name\":\"CPI Staff\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\"},\"headline\":\"Mastering Docker environment variables with Docker\",\"datePublished\":\"2025-09-14T07:11:42+00:00\",\"dateModified\":\"2025-09-14T07:11:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/\"},\"wordCount\":784,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/mastering-docker-environment-variables-with-docker-compose-today.png\",\"articleSection\":[\"Blog\",\"Docker\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/\",\"url\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/\",\"name\":\"Mastering Docker environment variables with Docker - CPI Consulting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/mastering-docker-environment-variables-with-docker-compose-today.png\",\"datePublished\":\"2025-09-14T07:11:42+00:00\",\"dateModified\":\"2025-09-14T07:11:45+00:00\",\"description\":\"Unlock the secrets of Docker with mastering Docker environment variables. Learn to use them confidently with Docker Compose.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#primaryimage\",\"url\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/mastering-docker-environment-variables-with-docker-compose-today.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/09\\\/mastering-docker-environment-variables-with-docker-compose-today.png\",\"width\":1536,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/2025\\\/09\\\/14\\\/mastering-docker-environment-variables-with-docker\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudproinc.com.au\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mastering Docker environment variables with Docker\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#website\",\"url\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/\",\"name\":\"Cloud Pro Inc - CPI Consulting Pty Ltd\",\"description\":\"Cloud, AI &amp; Cybersecurity Consulting | Melbourne\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#organization\",\"name\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\",\"url\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"width\":500,\"height\":500,\"caption\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\",\"name\":\"CPI Staff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"caption\":\"CPI Staff\"},\"sameAs\":[\"http:\\\/\\\/www.cloudproinc.com.au\"],\"url\":\"https:\\\/\\\/cloudproinc.azurewebsites.net\\\/index.php\\\/author\\\/cpiadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Mastering Docker environment variables with Docker - CPI Consulting","description":"Unlock the secrets of Docker with mastering Docker environment variables. Learn to use them confidently with Docker Compose.","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:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/","og_locale":"en_US","og_type":"article","og_title":"Mastering Docker environment variables with Docker","og_description":"Unlock the secrets of Docker with mastering Docker environment variables. Learn to use them confidently with Docker Compose.","og_url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/","og_site_name":"CPI Consulting","article_published_time":"2025-09-14T07:11:42+00:00","article_modified_time":"2025-09-14T07:11:45+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/cloudproinc.azurewebsites.net\/wp-content\/uploads\/2025\/09\/mastering-docker-environment-variables-with-docker-compose-today.png","type":"image\/png"}],"author":"CPI Staff","twitter_card":"summary_large_image","twitter_misc":{"Written by":"CPI Staff","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#article","isPartOf":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/"},"author":{"name":"CPI Staff","@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e"},"headline":"Mastering Docker environment variables with Docker","datePublished":"2025-09-14T07:11:42+00:00","dateModified":"2025-09-14T07:11:45+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/"},"wordCount":784,"commentCount":0,"publisher":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#organization"},"image":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/mastering-docker-environment-variables-with-docker-compose-today.png","articleSection":["Blog","Docker"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/","url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/","name":"Mastering Docker environment variables with Docker - CPI Consulting","isPartOf":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#primaryimage"},"image":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/09\/mastering-docker-environment-variables-with-docker-compose-today.png","datePublished":"2025-09-14T07:11:42+00:00","dateModified":"2025-09-14T07:11:45+00:00","description":"Unlock the secrets of Docker with mastering Docker environment variables. Learn to use them confidently with Docker Compose.","breadcrumb":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#primaryimage","url":"\/wp-content\/uploads\/2025\/09\/mastering-docker-environment-variables-with-docker-compose-today.png","contentUrl":"\/wp-content\/uploads\/2025\/09\/mastering-docker-environment-variables-with-docker-compose-today.png","width":1536,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/14\/mastering-docker-environment-variables-with-docker\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudproinc.com.au\/"},{"@type":"ListItem","position":2,"name":"Mastering Docker environment variables with Docker"}]},{"@type":"WebSite","@id":"https:\/\/cloudproinc.azurewebsites.net\/#website","url":"https:\/\/cloudproinc.azurewebsites.net\/","name":"Cloud Pro Inc - CPI Consulting Pty Ltd","description":"Cloud, AI &amp; Cybersecurity Consulting | Melbourne","publisher":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudproinc.azurewebsites.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudproinc.azurewebsites.net\/#organization","name":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd","url":"https:\/\/cloudproinc.azurewebsites.net\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/logo\/image\/","url":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","contentUrl":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","width":500,"height":500,"caption":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd"},"image":{"@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudproinc.azurewebsites.net\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e","name":"CPI Staff","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","caption":"CPI Staff"},"sameAs":["http:\/\/www.cloudproinc.com.au"],"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/author\/cpiadmin\/"}]}},"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/09\/mastering-docker-environment-variables-with-docker-compose-today.png","jetpack-related-posts":[{"id":53819,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/15\/build-lean-reliable-net-docker-images-for-production\/","url_meta":{"origin":53812,"position":0},"title":"Build Lean Reliable .NET Docker Images for Production","author":"CPI Staff","date":"September 15, 2025","format":false,"excerpt":"Learn how to build small, secure, and fast .NET Docker images using multi-stage builds, caching, and best practices that work in local dev and production.","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 1x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 1.5x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 2x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 3x, \/wp-content\/uploads\/2025\/09\/how-to-build-lean-reliable-net-docker-images-for-production.png 4x"},"classes":[]},{"id":53803,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/11\/the-benefits-of-using-docker-compose-for-teams-and-projects\/","url_meta":{"origin":53812,"position":1},"title":"The Benefits of Using Docker Compose for Teams and Projects","author":"CPI Staff","date":"September 11, 2025","format":false,"excerpt":"Learn how Docker Compose streamlines multi-container development, testing, and CI. Practical steps, examples, and best practices for technical teams.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 1x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 1.5x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 2x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 3x, \/wp-content\/uploads\/2025\/09\/the-benefits-of-using-docker-compose-for-teams-and-projects.png 4x"},"classes":[]},{"id":53820,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/15\/host-and-run-a-website-inside-docker-for-fast-portable-deploys\/","url_meta":{"origin":53812,"position":2},"title":"Host and Run a Website inside Docker for Fast, Portable Deploys","author":"CPI Staff","date":"September 15, 2025","format":false,"excerpt":"Learn how to containerise, serve, and secure a website with Docker. From first run to production-ready patterns, this guide covers images, volumes, networks, and TLS.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 1x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 1.5x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 2x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 3x, \/wp-content\/uploads\/2025\/09\/host-and-run-a-website-inside-docker-for-fast-portable-deploys.png 4x"},"classes":[]},{"id":53918,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/22\/securing-streamlit-environment-vars-with-toml\/","url_meta":{"origin":53812,"position":3},"title":"Securing Streamlit Environment Vars with TOML","author":"CPI Staff","date":"September 22, 2025","format":false,"excerpt":"Protect API keys and credentials in Streamlit using TOML-based secrets, safe local and cloud workflows, and CI\/CD patterns for repeatable, secure deployments.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png 1x, \/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png 1.5x, \/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png 2x, \/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png 3x, \/wp-content\/uploads\/2025\/09\/a-practical-guide-to-securing-streamlit-environment-vars-with-toml.png 4x"},"classes":[]},{"id":53790,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/09\/08\/keep-net-app-running-in-docker\/","url_meta":{"origin":53812,"position":4},"title":"Keep .NET App Running in Docker","author":"CPI Staff","date":"September 8, 2025","format":false,"excerpt":"Learn how to containerise a .NET app, start it automatically, and keep it running with Docker and Docker Compose\u2014production-friendly, developer-happy.","rel":"","context":"In &quot;.NET&quot;","block_context":{"text":".NET","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/net\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 1x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 1.5x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 2x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 3x, \/wp-content\/uploads\/2025\/09\/keep-your-net-app-running-in-docker-the-right-way-with-compose.png 4x"},"classes":[]},{"id":53710,"url":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/2025\/08\/25\/run-neo4j-with-docker-inside-github-codespaces\/","url_meta":{"origin":53812,"position":5},"title":"Run Neo4j with Docker inside GitHub Codespaces","author":"CPI Staff","date":"August 25, 2025","format":false,"excerpt":"Spin up Neo4j inside GitHub Codespaces using Docker and Docker Compose. Fast local graph development, zero installs on your laptop.","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/08\/run-neo4j-with-docker-inside-github-codespaces.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/08\/run-neo4j-with-docker-inside-github-codespaces.png 1x, \/wp-content\/uploads\/2025\/08\/run-neo4j-with-docker-inside-github-codespaces.png 1.5x, \/wp-content\/uploads\/2025\/08\/run-neo4j-with-docker-inside-github-codespaces.png 2x, \/wp-content\/uploads\/2025\/08\/run-neo4j-with-docker-inside-github-codespaces.png 3x, \/wp-content\/uploads\/2025\/08\/run-neo4j-with-docker-inside-github-codespaces.png 4x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=53812"}],"version-history":[{"count":1,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53812\/revisions"}],"predecessor-version":[{"id":53814,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/53812\/revisions\/53814"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media\/53813"}],"wp:attachment":[{"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=53812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=53812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudproinc.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=53812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}