【发布时间】:2022-01-23 23:46:28
【问题描述】:
我通过 AWS EC2 在 docker 容器中托管一个烧瓶应用程序,它将显示上传到它的文件的内容。
我面临一个奇怪的问题是我的应用程序没有暴露给外部世界,但它可以在 localhost 上运行。当我尝试点击我的机器的公共 ip 时,它显示“拒绝连接”(注意:安全组很好)
docker ps 命令显示我的容器在预期的端口号上运行良好。您能告诉我如何解决它以使其正常工作吗?提前致谢
Docker 版本 20.10.7,构建 f0df350
这是我的 Dockerfile,
FROM ubuntu:latest
RUN mkdir /testing
WORKDIR /testing
ADD . /testing
RUN apt-get update&&apt-get install -y pip
RUN pip install -r requirements.txt
CMD flask run
在我的 requirements.txt 文件中,我将烧瓶安装在 docker 中。
这是我的烧瓶代码和 html 文件,
from flask import Flask,render_template,request
app = Flask(__name__)
@app.route("/")
def file():
return render_template("index.html")
@app.route("/upload", methods= ['POST','GET'])
def test():
print("test")
if request.method == 'POST':
print("test3")
file = request.files['File'].read()
return file
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0')
index.html:
<html>
<body>
<form action = "http://<publiciIPofmachine>:5000/upload" method = "POST" enctype =
"multipart/form-data">
<input type = "file" name = "File" />
<input type = "submit" value = "Submit" />
</form>
</body>
</html>
码头日志:
服务 Flask 应用程序“应用程序”(延迟加载)
- 环境:生产 警告:这是一个开发服务器。不要在生产部署中使用它。 请改用生产 WSGI 服务器。
- 调试模式:开启
- 在所有地址上运行。 警告:这是一个开发服务器。不要在生产部署中使用它。
- 在http://172.17.0.2:5000/ 上运行(按 CTRL+C 退出)
这是我使用的 docker 命令,
docker build -t <name> .
docker run -d -t -p 5000:80 <imagename>
【问题讨论】:
标签: docker flask amazon-ec2