title: Docker-compose - setting environment variables that are not literals
body: <p>I have setup Jenkins within a Docker container and I am trying to access that my private Bitbucket repo with that server. I need to copy my SSH key into that container so that Bitbucket recognizes it and I can have my Jenkins server access the repo then.</p>
  
  <p>I have in my docker-compose.yml file the following:</p>
  
  <pre><code>services:
    jenkins:
      build: .
      volumes:
        - jenkins-data:/var/jenkins_home
      environment:
        - SSH_PRIVATE_KEY=$(cat ~/.ssh/id_rsa)
      ports:
        - "8080:8080"
        - "50000:50000"
  
  volumes:
    jenkins-data:
  </code></pre>
  
  <p>However, <code>echo $SSH_PRIVATE_KEY</code> gives <code>/.ssh/id_rsa</code> literally instead of the value stored inside. I have heard the problem with doing this inside the Dockerfile instead would be that it still can be viewed in one of the layers of the image that will be pushed.</p>
  
  <p>My question is how can I set the value of <code>SSH_PRIVATE_KEY</code> to the value of the contents of my file?</p>
  
  <p>I believe this could be a duplicate of <a href="https://stackoverflow.com/questions/50238621/how-to-set-environment-variable-into-docker-container-using-docker-compose">How to set environment variable into docker container using docker-compose</a> however that solution does not appear to change anything for me.</p>