ElasticBeanstalk Docker意外的暴露端口

时间:2018-07-07 03:53:56

标签: amazon-web-services docker elastic-beanstalk

问题

我正在尝试使用flask_restful在Docker容器内使用AWS Elastic Beanstalk部署测试API。我在下面粘贴了示例代码,以便大家都可以看到实际发生的情况。我不理解的奇怪之处是我的app.py正在运行,但它暴露在端口80而不是端口5000上,这是我在app.py app.run命令以及我的命令中都指定的dockerfile。我也没有在此环境中运行负载平衡器。我确信这清楚地记录在某处。但是我还没有找到。

dockerfile:

FROM ubuntu:14.04

   # Update packages
RUN apt-get update -y

# Install Python Setuptools
RUN apt-get install -y python-setuptools

# Install pip
RUN easy_install pip

# Add and install Python modules
ADD requirements.txt /src/requirements.txt
RUN cd /src; pip install -r requirements.txt

# Bundle app source
ADD . /src

# Expose
EXPOSE  5000

# Run
CMD ["python", "/src/app.py"]

app.py:

from flask import Flask
from flask_restful import Api, Resource

app = Flask(__name__)
api = Api(app)

workers = [
    {
        "workerid": "sample1",
        "iamid": "Pj9Cm8r&ve85Wm%u"
    },
]

class WorkerOnline(Resource):
    def get(self, name):
        for worker in workers:
            if(name == worker["workerid"]):
                return "Worker " + name + " Found", 200
        return "Worker not associated", 404

api.add_resource(WorkerOnline, "/worker/online/<string:name>")

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

0 个答案:

没有答案