Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Support for runArgs for `docker compose` scenario

未关闭
#39 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
docker, docker-compose
领域
devops

调研方向

首先查看 issue 中链接的 devcontainer.json 参考文档,以及示例中展示的现有 docker-compose 配置。跟踪在 dockerComposeFile 设置下如何调用 docker compose。完成的标准是:runArgs env-file 选项可以指向项目根目录的 .env 文件,而无需将其复制到 .devcontainer,也不会将整个文件暴露给容器。

由索引模型根据 Issue 内容生成。

描述

As a developer, I want to point docker compose to my (the correct) .env-file.

{
	"name": "Python 3 & Poetry",
	"dockerComposeFile": [
		"../../docker-compose.yml",
		"./docker-compose.yml"
	],
        "runArgs": ["--env-file=../../.env"],      <-- New Option
        ...
}
Discussed in https://github.com/orgs/devcontainers/discussions/36

Originally posted by bgloss March 10, 2023
I don't get the environment variables from my project's .env file into the docker-compose.ymlsetup with a pretty default project layout.

My project layout is as follows:

.devcontainer/
     devcontainer.json
     docker-compose.yml
     Dockerfile
.env

I want to have in docker-compose.yml a section to create a Postgres container with setting up the environment one by one: POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB and fill them with variables from the project's .env file. The relevant section in docker-compose.yml is:

  postgres:
    image: postgres:latest
    environment:
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_DB: ${POSTGRES_DB}

I do NOT want to have a copy of my .env file in the .devcontainer/ folder, as it is the case in some of the DevContainer templates. This would work, as in this case docker compose loads it by default. I don't want this organization, as the .env file is also needed by the project's code and expected in the project root.

I also don't want to expose the whole .env-file to my container, which I could do with the env_file option in the docker compose service description.

When building a container myself (just docker, no docker compose), I can add in devcontainer.json the option runArgs next to the option build giving the env-file information to docker: --env-file ../.env However, this is not possible when using a docker-compose setup in vscode and DevContainers with "dockerComposeFile": "docker-compose.yml".

https://containers.dev/implementors/json_reference/

At the command line docker compose --env-file ../.env up does the trick.

So, my questions:

  • Am I missing something?
  • Is this a missing feature in devcontainer.json?
主要语言
没有语言数据
星标
2
派生
1
PR 合并指标
30 天内没有已合并 PR

环境准备

我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

devcontainers/community 的其他 Issue

查看 devcontainers/community 的全部 Issue

相似的 Issue

更多 DevOps Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。