devcontainers / devcontainers/spec

Environment and pre-defined variables are not supported in `forwardPorts` and keys of `portsAttributes`

Aperta
#489 7 commenti 0 reazioni 1 assegnatario Rivendicata da @chrmarti Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
5.7k
Fork
496
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

To avoid hardcoding hostnames I am using environment variables, e.g. `${POSTGRES_HOSTNAME}`. This allows pointing application or any supplementary scripts to the correct host depending on the environment (e.g. in and out of dev container).
Same variables are used as `hostname:` in Docker Compose files:
```yaml
services:
postgres:
image: postgres:latest
hostname: ${POSTGRES_HOSTNAME}
...
...
```
And same variables should be used in `forwardPorts` and `portsAttributes` of dev container configuration:
```json
{
...
"forwardPorts": [
"${containerEnv:POSTGRES_HOSTNAME}:5432",
...
],
"portsAttributes": {
"${containerEnv:POSTGRES_HOSTNAME}:5432": {
...
},
...
},
...
}
```
Unfortunately, `forwardPorts` and `portsAttributes` don't support variables, so it needs to be hardcoded instead:
```json
{
...
"forwardPorts": [
"postgres:5432",
...
],
"portsAttributes": {
"postgres:5432": {
...
},
...
},
...
}
```
...meaning that hostname needs to be changed manually in two more places if the environment variable changes.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.