Using multi-line value in .env file in docker-compose

If you don’t mind not using the .env file (maybe that environment variable is used only in a single container). You can define environment variables directly inside docker-compose.yml and there, you can make full use of YAML formatting options. I.e.:

myservice:
  build: .
  environment:
    SSH_KEY: >
      --------- WHATEVER ----------
      randomkeybase64thingforyourse
      rvice
      ------- END WHATEVER --------

And as a side note, you don’t have to copy .env values inside the environment section. .env variables are used inside the docker-compose.yml file, but not in the container’s environment. However, you can do:

myservice:
  build: .
  env_file:
    # Files in this array have the same format as `.env` files, but they are
    # passed to container's environment instead being used inside this
    # `docker-compose.yml` file
    - variables.env
  environment:
    SSH_KEY: >
      --------- WHATEVER ----------
      randomkeybase64thingforyourse
      rvice
      ------- END WHATEVER --------

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)