{"id":25497462,"url":"https://github.com/perpetue237/docker-env-vars-example","last_synced_at":"2026-04-15T09:31:33.307Z","repository":{"id":254471422,"uuid":"846451019","full_name":"Perpetue237/docker-env-vars-example","owner":"Perpetue237","description":"A comprehensive example repository demonstrating how to manage and use environment variables in Docker, covering .env files, Dockerfile instructions, OS-level variables, and Docker Compose.","archived":false,"fork":false,"pushed_at":"2024-08-27T07:15:10.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-19T11:45:44.751Z","etag":null,"topics":["docker","docker-compose","environment-variables","python","security"],"latest_commit_sha":null,"homepage":"https://www.linkedin.com/in/perpetue-k-375306185","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Perpetue237.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-08-23T08:32:44.000Z","updated_at":"2024-08-29T08:24:33.000Z","dependencies_parsed_at":"2024-08-23T18:17:57.937Z","dependency_job_id":"93a20d0d-9e4a-41e4-84ae-97096d8952b0","html_url":"https://github.com/Perpetue237/docker-env-vars-example","commit_stats":null,"previous_names":["perpetue237/docker-env-vars-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Perpetue237/docker-env-vars-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perpetue237%2Fdocker-env-vars-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perpetue237%2Fdocker-env-vars-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perpetue237%2Fdocker-env-vars-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perpetue237%2Fdocker-env-vars-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Perpetue237","download_url":"https://codeload.github.com/Perpetue237/docker-env-vars-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Perpetue237%2Fdocker-env-vars-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31834510,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T07:17:56.427Z","status":"ssl_error","status_checked_at":"2026-04-15T07:17:30.007Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","environment-variables","python","security"],"created_at":"2025-02-19T01:20:04.335Z","updated_at":"2026-04-15T09:31:33.275Z","avatar_url":"https://github.com/Perpetue237.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Docker Environment Variables Examples\n\nThis repository demonstrates how to work with environment variables in Docker. It covers the following topics:\n\n1. **Using `.env` files**\n2. **Setting environment variables from the OS**\n3. **Passing environment variables via `Dockerfile`**\n4. **Using environment variables with `docker-compose.yml`**\n5. **Building Docker images with build arguments**\n\n## 1. Using `.env` Files\nYou can store environment variables in a [.env](.env) file and make them available to Docker.\n\n### Passing .env to Docker with docker run:\n```bash\ndocker run --env-file .env --rm my-image\n```\n\n### Expected Output:\n\n```bash\nMY_VARIABLE_FROM_OS: None\nMY_VARIABLE_FROM_ENV: Hello from .env file\nMY_VARIABLE_FROM_DOCKERFILE: Hello from Dockerfile!\nMY_VARIABLE_FROM_DC: None\nMY_BUILD_ARG (MY_VARIABLE): \nMY_BUILD_ARG_FROM_DC (MY_BUILD_ARG_FROM_DC): \n\n```\n### Using .env with Docker Compose:\nThe following shows how to make the `.env` available in the service `myapp`. \n\n```bash\nversion: '3.8'\n\nservices:\n  myapp:\n    env_file:\n      - .env\n\n```\nIn the section 4. we will see how to run the service and the expected output.\n\n## 2. Setting Environment Variables from the OS\n\nYou can pass environment variables from your OS to Docker containers. For example:\n\n```bash\nexport MY_VARIABLE_FROM_OS=\"Hello, from os!\"\ndocker run -e MY_VARIABLE_FROM_OS --rm my-image\n```\n### Expected Output:\n```bash\nMY_VARIABLE_FROM_OS: Hello, from os!\nMY_VARIABLE_FROM_ENV: None\nMY_VARIABLE_FROM_DOCKERFILE: Hello from Dockerfile!\nMY_VARIABLE_FROM_DC: None\nMY_BUILD_ARG (MY_VARIABLE): \nMY_BUILD_ARG_FROM_DC (MY_BUILD_ARG_FROM_DC): \n```\n\n## 3. Passing Environment Variables via `Dockerfile`\n\nYou can use the `ENV` instruction in a [Dockerfile](Dockerfile) to set environment variables that will be available during runtime. Build the docker image using:\n\n```bash\ndocker build  -t my-image .\n```\nAfter building your Docker image, you can run the container and check the output of the environment variables by using the following command:\n\n```bash\ndocker run --rm my-image\n```\n\n### Expected Output:\n```bash\nMY_VARIABLE_FROM_OS: None\nMY_VARIABLE_FROM_ENV: None\nMY_VARIABLE_FROM_DOCKERFILE: Hello from Dockerfile!\nMY_VARIABLE_FROM_DC: None\nMY_BUILD_ARG (MY_VARIABLE): \nMY_BUILD_ARG_FROM_DC (MY_BUILD_ARG_FROM_DC):\n```\n\n## 4. Using Environment Variables with `docker-compose.yml`\n\nYou can define environment variables directly in your [docker-compose.yml](docker-compose.yml) file.\nThese variables are passed to the container when it starts. \n\nAfter setting up your [docker-compose.yml](docker-compose.yml) and [Dockerfile](Dockerfile), you can run your service with:\n\n```bash\ndocker-compose up --build\n```\n\nThis command will build the Docker image (taking into account any build arguments), start the container, and apply all the environment variables from the .env file, docker-compose.yml, and Dockerfile.\n\n### Expected Output:\n\n```bash\nCreating docker-env-vars-example_myapp_1 ... done\nAttaching to docker-env-vars-example_myapp_1\nmyapp_1  | MY_VARIABLE_FROM_OS: None\nmyapp_1  | MY_VARIABLE_FROM_ENV: None\nmyapp_1  | MY_VARIABLE_FROM_DOCKERFILE: Hello from Dockerfile!\nmyapp_1  | MY_VARIABLE_FROM_DC: Hello from docker-compose.yml\nmyapp_1  | MY_BUILD_ARG (MY_VARIABLE): \nmyapp_1  | MY_BUILD_ARG_FROM_DC (MY_BUILD_ARG_FROM_DC): Hello build build ARG from docker-compose.yml\n\n```\n\n## 5. Building Docker Images with Build Arguments\n\nYou can pass build-time arguments using the `ARG` instruction in the [Dockerfile](Dockerfile).\n\nBuild with arguments:\n\n```bash\ndocker build --build-arg MY_BUILD_ARG=\"Hello during build from command line\" -t my-image .\n```\n\nAfter building your Docker image, you can run the container and check the output of the environment variables by using the following command:\n\n```bash\ndocker run --rm my-image\n```\n\n### Expected Output:\n```bash\nMY_VARIABLE_FROM_OS: None\nMY_VARIABLE_FROM_ENV: None\nMY_VARIABLE_FROM_DOCKERFILE: Hello from Dockerfile\nMY_VARIABLE_FROM_DC: None\nMY_BUILD_ARG (MY_VARIABLE): Hello during build from command line\nMY_BUILD_ARG_FROM_DC (MY_BUILD_ARG_FROM_DC):\n```\n\nBuild arguments (ARG) are only available during the build process. However, you can pass them to runtime environment variables using ENV if needed.\n\n## License\n\nDistributed under the Apache License. See [LICENSE](LICENSE) for more information.\n\n## Contact\n\n[Perpetue Kuete Tiayo](https://www.linkedin.com/in/perpetue-k-375306185)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperpetue237%2Fdocker-env-vars-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperpetue237%2Fdocker-env-vars-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperpetue237%2Fdocker-env-vars-example/lists"}