diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9e87f23 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Use an official Python runtime as the base image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /app + +# Copy the requirements file into the container +COPY requirements.txt . + +# Install the required packages +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the rest of the application code into the container +COPY . . + +# Set environment variables +ENV FLASK_APP=app.py +ENV FLASK_RUN_HOST=0.0.0.0 + +# Expose the port on which the app will run +EXPOSE 5000 + +# Run the Flask application +CMD ["flask", "run", "--host=0.0.0.0"] diff --git a/README.md b/README.md index d54a334..6e61ee3 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ flask run Go to http://127.0.0.1:5000/ +or you can use `docker` to run this project: +``` +docker-compose up +``` + ## More details 关于这个项目的详细介绍:[Flask实践:计算器](https://zhuanlan.zhihu.com/p/24120882) 更多关于Flask的原创优质内容,欢迎关注[Hello, Flask!——知乎专栏](https://zhuanlan.zhihu.com/flask) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..36ccd74 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +services: + calculator: + build: . + container_name: calculator + ports: + - "5000:5000" + networks: + - calculator-network + +networks: + calculator-network: + driver: bridge \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 99b3df3..133d7e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,5 @@ Werkzeug==0.13 # deploy gunicorn==19.5.0 gevent +markupsafe==2.0.1 +itsdangerous==2.0.1