dev-environments icon indicating copy to clipboard operation
dev-environments copied to clipboard

Environment Variables are not evaluated

Open hegerdes opened this issue 4 years ago • 1 comments

When creating a docker-compose.yaml file in .docker this file is not allowed to use environment variables to set container environment variables or their ports when a .env file is present

For example:

version: '3.1'
services:
  db:
    image: postgres
    environment:
      POSTGRES_PASSWORD: ${POSGRES_PW}
      POSTGRES_USER: ${POSGRES_USER}
      POSTGRES_DB: ${POSGRES_DB}
    ports:
      - ${POSGRES_DB}:5432
#.env
POSGRES_PW=MySecureSQLPW
POSGRES_USER=MyUser
POSGRES_DB=MyDB
POSGRES_PORT=5432

Does NOT work. The resulting devenvs-docker-compose.yaml looks like:

services:
  db:
    environment:
      POSTGRES_DB: ""
      POSTGRES_PASSWORD: ""
      POSTGRES_USER: ""
    image: postgres
    labels:
      com.docker.devenvironments.compose: "true"
      com.docker.devenvironments.name: OpenMP
    networks:
      default: null
    ports:
    - mode: ingress
      target: 5432
      published:
      protocol: tcp

This is invalid due to empy ports values

Expected behavior Either evaluate the environment variables and set them in the devenvs-docker-compose.yaml or throw an error that .env file variables are not supported.

Desktop (please complete the following information):

  • OS: Windows 10 Pro
  • Version: Docker version 20.10.8, build 3967b7d

Also, please avoid platform dependent and absolut paths in devenvs-docker-compose.yaml. For example:

# Generated by Docker
    build:
      context: D:\Dev\OpenMP\OpenMP_backend
      dockerfile: D:\Dev\OpenMP\OpenMP_backend\.devcontainer\Dockerfile

Dont use absolut Windows paths.

hegerdes avatar Sep 25 '21 00:09 hegerdes

Hello @hegerdes

Thanks for you feedback! We're currently working to use Compose as the default file format to define/configure Dev Environments, so we should fix your issue with .env file. The devenvs-docker-compose.yaml is a temporary Compose file generated specifically for runtime, it doesn't have any other purpose than that and will be deleted with your Dev Environment.

glours avatar Oct 06 '21 08:10 glours