Answers: <p>Use environment variables on your host that are read by your <code>docker-compose.yml</code> file.  There are a couple ways to accomplish this.  One way is to create a <code>.env</code> file on the host that contains your variables.  Docker Compose will read these variables and apply them to your configuration.</p>
  
  <p>Alternatively, or in conjunction with a <code>.env</code> file, you can set environment variables in your shell.  These variables will be applied the same way as those read from a <code>.env</code> file and actually take precedence.</p>
  
  <p>Read more here: <a href="https://docs.docker.com/compose/environment-variables/" rel="nofollow noreferrer">https://docs.docker.com/compose/environment-variables/</a></p>
  
Answers: CC BY-SA 4.0
Answers: 2019-03-29T17:57:19.083Z
Answers: Just to be clear, by host you mean the VPS where my sites are running? So in `/var/www/html/mysite.co.uk/` I'll have a `.env` file with the JSON where the keys match the environmental variables that my application is expecting?
Answers: J86
Answers: CC BY-SA 4.0
Answers: 2019-03-29T18:44:07.123Z
Answers: Yes, the host where you execute `docker-compose up` will need the `.env` file in the current working directory. Those variables must match the variables declared in your compose file.
Answers: swysocki
Answers: CC BY-SA 4.0
Answers: 2019-03-29T19:43:48.707Z
Answers: Thank you for the clarification @swysocki, I'm getting an issue about whitespace! I've updated the question.
Answers: J86
Answers: CC BY-SA 4.0
Answers: 2019-03-29T20:34:14.620Z
Answers: Thanks, I figured it out. I was using `var: value` instead of `var=value`.
Answers: J86
Answers: CC BY-SA 4.0
Answers: 2019-03-29T17:28:01.690Z
Answers: 2019-03-29T17:28:01.690Z
Answers: swysocki
Body: <p>I am fairly new to DevOps. I have managed to build myself a CI/DI pipeline for my <a href="https://github.com/JwanKhalaf/Bejebeje.Identity" rel="nofollow noreferrer">open source project</a>.</p>
  
  <p>As soon as I check-in some code into GitHub, Travis CI takes over, it builds a fresh docker image of my code, pushes it to DockerHub, then the <code>after_success</code> step within <a href="https://github.com/JwanKhalaf/Bejebeje.Identity/blob/develop/.travis.yml" rel="nofollow noreferrer">my <code>.travis.yml</code></a> connects to my VPS via SSH, and runs a script on there which basically does a <code>docker-compose down</code> followed by a <code>docker-compose pull &amp;&amp; docker compose up</code>.</p>
  
  <p>All seems to be working correctly. But I have an issue with <a href="https://github.com/JwanKhalaf/Bejebeje.Identity/blob/develop/docker-compose.yml" rel="nofollow noreferrer">my <code>docker-compose.yml</code></a>. Right now as you can see, it has all my environmental variables. Those are considered secret information. How do I hide them from the <code>docker-compose.yml</code> file whilst having everything still working as before?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I went and created myself a <code>variables.env</code> file in the same directory as the <code>docker-compose.yml</code>. Inside the <code>.env</code> file, I put my old variables, for example:</p>
  
  <pre><code>Database__DefaultConnectionString: "Server=database;Port=5432;Database=bejebeje_identity;User Id=postgres;Password=admin;"
  </code></pre>
  
  <p>But in Travis CI I get the following error:</p>
  
  <blockquote>
    <p>environment variable name 'Database__DefaultConnectionString: "Server' may not contains whitespace.</p>
  </blockquote>
  
Tags: <docker-compose><travis-ci><servers>
Title: How do you hide sensitive information held in variables on a docker-compose file
UserDisplayName: J86
ThreadText: # How do you hide sensitive information held in variables on a docker-compose file
  
  (Asked by: username_0 on 2019-03-29)
  
  I am fairly new to DevOps. I have managed to build myself a CI/DI pipeline for my [open source project](https://github.com/JwanKhalaf/Bejebeje.Identity).
  
  As soon as I check-in some code into GitHub, Travis CI takes over, it builds a fresh docker image of my code, pushes it to DockerHub, then the `after_success` step within [my `.travis.yml`](https://github.com/JwanKhalaf/Bejebeje.Identity/blob/develop/.travis.yml) connects to my VPS via SSH, and runs a script on there which basically does a `docker-compose down` followed by a `docker-compose pull && docker compose up`.
  
  All seems to be working correctly. But I have an issue with [my `docker-compose.yml`](https://github.com/JwanKhalaf/Bejebeje.Identity/blob/develop/docker-compose.yml). Right now as you can see, it has all my environmental variables. Those are considered secret information. How do I hide them from the `docker-compose.yml` file whilst having everything still working as before?
  
  **UPDATE**
  
  I went and created myself a `variables.env` file in the same directory as the `docker-compose.yml`. Inside the `.env` file, I put my old variables, for example:
  
  ```
  Database__DefaultConnectionString: "Server=database;Port=5432;Database=bejebeje_identity;User Id=postgres;Password=admin;"
  
  ```
  
  But in Travis CI I get the following error:
  
  > environment variable name 'Database\_\_DefaultConnectionString: "Server' may not contains whitespace.
  
  **Tags:** docker-compose, travis-ci, servers
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-03-29. Score: 4 | Accepted answer
  
  Use environment variables on your host that are read by your `docker-compose.yml` file. There are a couple ways to accomplish this. One way is to create a `.env` file on the host that contains your variables. Docker Compose will read these variables and apply them to your configuration.
  
  Alternatively, or in conjunction with a `.env` file, you can set environment variables in your shell. These variables will be applied the same way as those read from a `.env` file and actually take precedence.
  
  Read more here: <https://docs.docker.com/compose/environment-variables/>
  
  > **Comments:**
  > **username_0**: Just to be clear, by host you mean the VPS where my sites are running? So in `/var/www/html/mysite.co.uk/` I'll have a `.env` file with the JSON where the keys match the environmental variables that my application is expecting?  
  > **username_1**: Yes, the host where you execute `docker-compose up` will need the `.env` file in the current working directory. Those variables must match the variables declared in your compose file.  
  > **username_0**: Thank you for the clarification @username_1, I'm getting an issue about whitespace! I've updated the question.  
  > **username_0**: Thanks, I figured it out. I was using `var: value` instead of `var=value`.  
  
  ---
  
  