title: How to get port of docker-compose from env_file?
body: <p>I want to use port number defined in env file, is it possible?
  The below is the content of my docker-compose.yml:</p>
  
  <pre><code>version: '3'
  services:
    flask:
      build:
        context: ./flask
        dockerfile: Dockerfile_flask
      env_file:
       - env_file.env
      ports:
       #- "5000:5000"
       - "${PORT}:${PORT}"  # I want to set port defined in the env file
      volumes:
        - ./logs:/app/flask/log
      restart: always
  </code></pre>
  
  <p>And this is the content of env_file.env</p>
  
  <pre><code>PORT=5000
  </code></pre>
  
  <p>But some errors raised:</p>
  
  <pre><code>WARNING: The PORT variable is not set. Defaulting to a blank string.
  ERROR: The Compose file './docker-compose.yml' is invalid because:
  services.flask.ports is invalid: Invalid port ":", should be [[remote_ip:]remote_port[-remote_port]:]port[/protocol]
  </code></pre>
  
  <p>If it's possible, how should I do it? Thanks</p>
  
  <p>@lvthillo, thanks for your previous response. But I have another problem that the port can't be accessed in my flask app. The codes are listed as below</p>
  
  <pre><code>import os
  from flask import Flask
  
  application = Flask(__name__)
  
  print(os.getenv("PORT")) # this is None
  my_port = int(os.getenv("PORT", 5000)) # so my_port here is 5000, but I want it to be 5002 defined in .env
  
  @application.route("/api/test", methods=['POST'])
  def index():
      print('hello')
  
  if __name__ == "__main__":
      application.run(host="0.0.0.0", port=my_port)
  </code></pre>
  
  <p>Because the flask app need to run with the same port as the container. Is there any way that I can set the port in env file for both docker-compose and my flask app? Thanks</p>