devcontainers / devcontainers/spec
Environment and pre-defined variables are not supported in `forwardPorts` and keys of `portsAttributes`
- 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.