Я новичок в aws и особенно docker, поэтому я перешел по этой ссылке, чтобы понять, что такое разработка веб-приложения - https://aws.amazon.com/getting-started/hands-on/build-modern-app-fargate-lambda-dynamodb-python/module-two/
Я застрял в момент, когда он просит нас протестировать службу локально с помощью команды 'docker run' (в модуле - 2), когда я запускаю команду, я получаю 'ImportError'.
Вот мой код -сниппеты .... пожалуйста, помогите мне! MythicalMysfitsService.py -
from flask import Flask, jsonify, json, Response, request
from flask_cors import CORS
# A very basic API created using Flask that has two possible routes for requests.
app = application = Flask(__name__)
CORS(application)
# The service basepath has a short response just to ensure that healthchecks
# sent to the service root will receive a healthy response.
@app.route("/")
def healthCheckResponse():
return jsonify({"message" : "Nothing here, used for health check. Try /mysfits instead."})
# The main API resource that the next version of the Mythical Mysfits website
# will utilize. It returns the data for all of the Mysfits to be displayed on
# the website. Because we do not yet have any persistent storage available for
# our application, the mysfits are simply stored in a static JSON file. Which is
# read from the the filesystem, and directly used as the service response.
@app.route("/mysfits")
def getMysfits():
# read the mysfits JSON from the listed file.
response = Response(open("mysfits-response.json").read())
# set the Content-Type header so that the browser is aware that the response
# is formatted as JSON and our frontend JavaScript code is able to
# appropriately parse the response.
response.headers["Content-Type"]= "application/json"
return response
# Run the service on the local server it has been deployed to,
# listening on port 8080.
if __name__ == "__main__":
application.run(host="0.0.0.0", port=8080)
Dockerfile -
FROM ubuntu:latest
RUN echo Updating existing packages, installing and upgrading python and pip.
RUN apt-get update -y
RUN apt-get install -y python3-pip python-dev build-essential
RUN pip3 install --upgrade pip
RUN echo Copying the Mythical Mysfits Flask service into a service directory.
COPY ./service /MythicalMysfitsService
WORKDIR /MythicalMysfitsService
RUN echo Installing Python packages listed in requirements.txt
RUN pip3 install -r ./requirements.txt
RUN echo Starting python and starting the Flask service...
ENTRYPOINT ["python"]
CMD ["mythicalMysfitsService.py"]
docker сборка -
ec2-user:~/environment/aws-modern-application-workshop/module-2/app (python) $ docker build . -t 054166015944.dkr.ecr.us-east-2.amazonaws.com/mythicalmysfits/service:latest
ВЫХОД -
Sending build context to Docker daemon 14.85kB
Step 1/14 : FROM ubuntu:latest
---> 1d622ef86b13
Step 2/14 : RUN echo Updating existing packages, installing and upgrading python and pip.
---> Using cache
---> 7cdaa818c9c2
Step 3/14 : RUN apt-get update -y
---> Using cache
---> a1fd46891d1e
Step 4/14 : RUN apt-get install -y python3-pip python-dev build-essential
---> Using cache
---> f81dc75dfc3f
Step 5/14 : RUN pip3 install --upgrade pip
---> Using cache
---> 0cee88c88f43
Step 6/14 : RUN echo Copying the Mythical Mysfits Flask service into a service directory.
---> Using cache
---> 709b50aac794
Step 7/14 : COPY ./service /MythicalMysfitsService
---> Using cache
---> f70454638e83
Step 8/14 : WORKDIR /MythicalMysfitsService
---> Using cache
---> 418a08d8ac32
Step 9/14 : RUN echo Installing Python packages listed in requirements.txt
---> Using cache
---> 03659d0cb00e
Step 10/14 : RUN pip3 install -r ./requirements.txt
---> Using cache
---> cb65480b6104
Step 11/14 : RUN echo Starting python and starting the Flask service...
---> Using cache
---> 89738a63f437
Step 12/14 : ENTRYPOINT ["python"]
---> Using cache
---> 97b4f200a571
Step 13/14 : CMD ["mythicalMysfitsService.py"]
---> Using cache
---> a22fe5fb5bdb
Step 14/14 : RUN unset -v PYTHONPATH
---> Using cache
---> f43930d6410a
Successfully built f43930d6410a
Successfully tagged 054166015944.dkr.ecr.us-east-2.amazonaws.com/mythicalmysfits/service:latest
docker запустить для тестирования службы локально -
$ docker run -p 8080:8080 054166015944.dkr.ecr.us-east-2.amazonaws.com/mythicalmysfits/service:latest
ошибка -
Traceback (most recent call last):
File "mythicalMysfitsService.py", line 1, in <module>
from flask import Flask, jsonify, json, Response, request
ImportError: No module named flask
проверено на flask с использованием flask --version
ВЫХОД -
Flask 1.0.4
Werkzeug 1.0.0
Итак, я установлен 'flask', но по-прежнему отображается сообщение Нет модуля с именем flask.