title: Best way to run multiple flask apps in a single docker container
body: <p>On a T2-Micro Instance on AWS/EC2 -</p>
  
  <p>I have built four Docker containers as show in the .yaml file below.</p>
  
  <p>These are:</p>
  
  <ol>
  <li>Nginx</li>
  <li>economy (app1)</li>
  <li>elections (app2)</li>
  <li>social (app3)</li>
  </ol>
  
  <p>There are gunicorn web servers in each of the three app containers serving 1 flask app. These are Plot.ly/Dash apps.</p>
  
  <p>As one might see, this takes a container for each app which gets bulky after three and starts to consume too much memory on the T2-Micro Instance.</p>
  
  <p>What would be ideal is if each app container ie: economy, elections, social etc. could have multiple flask apps within, using port iteration such as 5000, 5001, 5002 etc. They would all be addressable by unique port numbers which could be enumerated in the .yaml file.</p>
  
  <p>The use of single containers, single stacks of gunicorn, flask and dependent packages would reduce the memory requirements for individual containers allowing me to load up more apps on a single ec2 instance.</p>
  
  <p>The .yaml file below:</p>
  
  <pre><code>version: '2.1'
  
  services:
    economy:
      container_name: economy
      hostname: economy
      restart: always
      build: economy
      networks:
        tsworker-net:
      expose:
        - "8000"
      volumes:
        - ./data:/tmp/data:ro
      command: gunicorn -w 1 -b :8000 economy:server
  
    elections:
      container_name: elections
      hostname: elections
      restart: always
      build: elections
      networks:
        tsworker-net:
      expose:
        - "8500"
      volumes:
        - ./data:/tmp/data:ro
        - ./assets:/tmp/assets:ro
      environment:
        - FLASK_ENV=development
      command: gunicorn --log-level debug -w 1 -b :8500 elections:server
  
    social:
      container_name: social
      hostname: social
      restart: always
      build: social
      networks:
        tsworker-net:
      expose:
      - "9000"
      volumes:
        - ./data:/tmp/data:ro
      command: gunicorn -w 1 -b :9000 social:server # was 8000
  
    nginx:
      image: nginx:1.15
      container_name: nginx
      hostname: nginx
      restart: unless-stopped
      networks:
        tsworker-net:
      ports:
        - 80:80
        - 443:443
      volumes:
        - ./nginx/nginx.http.conf:/etc/nginx/conf.d/default.conf:ro
        - /etc/letsencrypt/etc:/etc/letsencrypt
        - /etc/letsencrypt/www:/var/www/letsencrypt
      environment:
        - TZ=UTC
      depends_on:
        - economy
        - elections
        - social
  
  networks:
    tsworker-net:
      driver: bridge
  </code></pre>
  
  <p>Any help with this will be highly appreciated.</p>