Код: Выделить всё
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == '__main__':
app.run(host="127.0.0.1", debug=True, port=8080)
Это мой Dockerfile:
Код: Выделить всё
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /hello_world
# Copy the current directory contents into the container at /app
ADD . /hello_world
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
EXPOSE 8080
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "hello_world.py"]
Код: Выделить всё
Flask
Я могу успешно создать образ с помощью docker build -t hello_world ».
Запуск его с помощью docker run -p 8080:8080 -t hello_world дает мне следующий результат:
Код: Выделить всё
Serving Flask app "hello_world" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 985-433-141
Подробнее здесь: https://stackoverflow.com/questions/517 ... -container
Мобильная версия