Hi team,
I have created a simple Dockerfile as follow
FROM python:3
RUN apt-get update -y &&
apt-get install -y python3-pip python-dev
WORKDIR /app
RUN pip install Flask requests python-dotenv
COPY . .
EXPOSE 5000
CMD [“python”, “./sent_analisys.py”]
It seems that image is built properly but the container does not start and the logs are not available for throubleshooting
1) Docker build
danilo.alexandre@RO-DALEXAND-10 MINGW64 ~/OneDrive - Nuance/Nuance/Udemy/Docker/azure_aci/flask
$ docker build -t analysis_sentiment .
[+] Building 8.7s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 32B 0.1s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for Docker Hub 8.1s
=> [1/5] FROM Docker Hub 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 26.35kB 0.0s
=> CACHED [2/5] RUN apt-get update -y && apt-get install -y python3-pip python-dev 0.0s
=> CACHED [3/5] WORKDIR /app 0.0s
=> CACHED [4/5] RUN pip install Flask requests python-dotenv 0.0s
=> [5/5] COPY . . 0.1s
=> exporting to image 0.3s
=> => exporting layers 0.2s
=> => writing image sha256:c8edee63f23e65054396b69f1cae5459245b726fa359ff7dae5410284ab9fc28 0.0s
=> => naming to Docker Hub 0.0s
Use ‘docker scan’ to run Snyk tests against images to find vulnerabilities and learn how to fix them
danilo.alexandre@RO-DALEXAND-10 MINGW64 ~/OneDrive - Nuance/Nuance/Udemy/Docker/azure_aci/flask
2) Docker Run
danilo.alexandre@RO-DALEXAND-10 MINGW64 ~/OneDrive - Nuance/Nuance/Udemy/Docker/azure_aci/flask
$ docker run -d -p 5001:5000 --name analysis_sent_container analysis_sentiment
d3b254aa054b8bdf3935c9cf2a2c055d9304f393ce393d3ecaf5deb0361b2689
3) Docker ps
danilo.alexandre@RO-DALEXAND-10 MINGW64 ~/OneDrive - Nuance/Nuance/Udemy/Docker/azure_aci/flask
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3) Logs are empty
danilo.alexandre@RO-DALEXAND-10 MINGW64 ~/OneDrive - Nuance/Nuance/Udemy/Docker/azure_aci/flask
$ docker logs analysis_sent_container
Phyton app (sent_analisys.py) for your reference:
#from os import name
from flask import Flask
from flask import request
import json
import requests
from dotenv import load_dotenv
import os
app = Flask(name)
@app.route(‘/sentimentAnalysis’, methods=[‘GET’,‘POST’])
def sentiment_analysis():
Gets the input json from the Mix request
try:
userText = ''
sourceLanguage = ''
mixContent = request.get_json(force=True)
userText = mixContent['userText']
sourceLanguage = mixContent['sourceLanguage']
print('teste')
except:
None, print ("stopped here")
#Azure API EndPoint
sentimentAnalysesEndPoint = 'https://testing-language-service.cognitiveservices.azure.com/text/analytics/v3.1/sentiment?'
urlParameters = {
# Request parameters
'opinionMining':'false'
}
#Load Azure Subscription Key
load_dotenv("AzureKey.env")
AzureKey = os.environ.get('AzureSubsKey')
urlHeaders = {
# Request headers
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': AzureKey,
}
#JSON required by Azure Resource, including text to be analized and language source
jsonRequired = {"documents":[{"id":"documentId","text":userText,"language":sourceLanguage}]}
# API Call
r = requests.post(sentimentAnalysesEndPoint, headers=urlHeaders, params=urlParameters, json=jsonRequired)
if (r.status_code !=200):
status_code = str (r.status_code)
return 'Not possible to process the API Call: '+status_code
else:
try:
sentimentAnalysesResponse = json.loads(r.text)
sentimentAnalysesOutput = {}
sentimentAnalysesMixOuput = []
for i in sentimentAnalysesResponse['documents'][0]['sentences']:
sentimentAnalysesOutput ['sentiment'] = i['sentiment']
sentimentAnalysesOutput ['confidenceScores'] = i['confidenceScores']
sentimentAnalysesOutput ['text'] = i['text']
sentimentAnalysesMixOuput.append(sentimentAnalysesOutput)
except:
None
return {'sentimentListOutput': sentimentAnalysesMixOuput, 'returnCode':0}
I am totally blocked so any help on how to fix/throubleshoot it will be very welcome
Thanks and Regards,
Danilo R. Alexandre