devcontainers / devcontainers/community

Support for runArgs for `docker compose` scenario

Aperta
#39 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
2
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.yml`setup 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`?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start by reviewing the devcontainer.json reference linked in the issue and the existing docker-compose configuration shown in the examples. Trace how docker compose is invoked for a dockerComposeFile setup. Done means a runArgs env-file option can point to the project-root .env file without copying it into .devcontainer or exposing the entire file to the container.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
docker, docker-compose
Ambito
devops
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.