简而言之,我问题是我无法访问在docker contrainer中运行的flask应用程序。
我有 flask 应用程序
@app.route('/')
def home():
return "test"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
我的dockerfile
# start by pulling the python image
FROM python:3.8
WORKDIR /app
# copy the requirements file into the image
COPY requirements.txt .
RUN pip install -r requirements.txt
# copy every content from the local file to the image
COPY . /app
CMD [ "python", "app.py" ]
我的docker compose
version: '3'
services:
python-backend:
build: ./LAB3
container_name: python-backend
ports:
- "5000:5000"
文件夹结构labDocker(包含docker compose)-〉LAB 3(包含dockerfile)
当我运行我的应用程序是启动没有任何错误,请参阅下面的日志
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
Press CTRL+C to quit
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
当我试图通过 Postman 发送请求时,我收到错误:
GET http://127.0.0.1:5000/
Error: socket hang up
Request Headers
User-Agent: PostmanRuntime/7.31.3
Accept: */*
Postman-Token: e54441e3-9ec4-427c-8202-e09f5cd92500
Host: 127.0.0.1:5000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
我在这个论坛上浏览了几个有类似问题的主题,但都没有解决我的问题,如果你有任何建议,请让我知道
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ae6ad71c8542 labdocker_python-backend "python app.py" 15 minutes ago Up 15 minutes 0.0.0.0:5000->5000/tcp python-backend
1条答案
按热度按时间bzzcjhmw1#
所以问题是不知何故docker没有拾取我在flask www.example中所做的更改 www.example.com 文件,并没有任何想法
所以我用这个命令重新构建了图像
现在一切正常