title: How to pass environment variable from docker-compose to the project?
body: <p>I'm using AWS ECS repository for docker images.</p>
  
  <p>My <code>docker-compose.yml</code> file looks like:</p>
  
  <pre><code>version: "3"
  services:
    my-front-end:
      image: myFrontEndImage:myTag
      links:
        - my-back-end
      ports:
        - "8080:8080"
      logging:
        driver: 'json-file'
        options:
          max-size: "50m"
    my-back-end:
      image: myBackEndImage:myTag
      ports:
        - "3000:3000"
      logging:
        driver: 'json-file'
        options:
          max-size: "50m"
  </code></pre>
  
  <p>And what I need is, to be able to pass a environment variable from the docker-compose file, into my docker image. </p>
  
  <p>What I tried was adding the lines for environment (following the <a href="https://docs.docker.com/compose/environment-variables/#the-env-file" rel="nofollow noreferrer">example</a>).</p>
  
  <pre><code>version: "3"
  services:
    my-front-end:
      image: myFrontEndImage:myTag
      links:
        - my-back-end
      environment:
        - BACKEND_SERVER_PORT=3001
      ports:
        - "8080:8080"
      logging:
        driver: 'json-file'
        options:
          max-size: "50m"
    my-back-end:
      image: myBackEndImage:myTag
      ports:
        - "3000:3000"
      logging:
        driver: 'json-file'
        options:
          max-size: "50m"
  </code></pre>
  
  <p>And then in my project (which is a VueJS project) I'm trying to access it by <code>process.env.BACKEND_SERVER_PORT</code>. But I do not see my value and when I tried <code>console.log(process.env);</code> I see that it has only the value <code>{NODE_ENV: "development"}</code>.</p>
  
  <p>So my question here is, how to pass the env variable from the docker-compose to my docker image, so that I will be able to use it inside my project?</p>
  
  <p>Everything in the project works fine, I'm working on this project a long time and docker-compose file works, it's just, now when I have a need of adding this environment variable, I can't make it work.</p>
  
  <p><strong>EDIT:</strong> adding few more files, per request in comment.</p>
  
  <p>The <code>.Dockerfile</code> for <code>my-front-end</code> looks like:</p>
  
  <pre><code>FROM node:8.11.1
  WORKDIR /app
  COPY package*.json ./
  RUN npm i npm@latest -g &amp;&amp; \
      npm install
  COPY . .
  CMD ["npm", "start"]
  </code></pre>
  
  <p>As mentioned, this is an <code>VueJS</code> application and here is the part of <code>package.json</code> which you may be interested in:</p>
  
  <pre><code>"scripts": {
    "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "build": "node build/build.js"
  },
  </code></pre>
  
  <p>While the <code>.Dockerfile</code> for <code>my-back-end</code> looks like:</p>
  
  <pre><code>FROM node:8.11.1
  WORKDIR /app/server
  COPY package*.json ./
  RUN npm i npm@latest -g &amp;&amp; \
      npm install
  COPY . .
  CMD ["npm", "start"]
  </code></pre>
  
  <p>My back-end is actually an <code>express.js</code> app that is listening on a separate port and the app is placed in a folder <code>server</code> under the root of the project.
  Here is the part of <code>package.json</code> which you may be interested in:</p>
  
  <pre><code>"scripts": {
    "start": "nodemon src/app.js",
    "test": "echo \"Error: no test specified\" &amp;&amp; exit 1"
  },
  </code></pre>