1

i am trying to build a flask rest service that will output random numbers in json format , i am trying to containerize and deploy this in docker.

I have run into a few issues here, basically the python rest service works on my local but when i deploy this in docker it does not work at all

below is my main.py

from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
from flask.ext.jsonpify import jsonify
import random

app = Flask(__name__)
api = Api(app)

class generate_appid:
    def get_now(self):
        number_array=[0]
        for x in range(10):
            number_array.append(random.randint(0,9))
        number_string=''.join(map(str, number_array))
        return number_string
class appid(Resource):
    def get(self):
        number_initialise = generate_appid()
        appid1=number_initialise.get_now()
        return {'appid': appid1 }
api.add_resource(appid, '/appid')
if __name__=='__main__':
    app.run(port=5000)

requirements.txt

aniso8601==1.2.0
appdirs==1.4.0
click==6.7
Flask==0.12
Flask-Jsonpify==1.5.0
Flask-RESTful==0.3.5
Flask-SQLAlchemy==2.1
itsdangerous==0.24
Jinja2==2.9.5
MarkupSafe==0.23
packaging==16.8
pyparsing==2.1.10
python-dateutil==2.6.0
pytz==2016.10
six==1.10.0
SQLAlchemy==1.1.5
Werkzeug==0.11.15

and Dockerfile

FROM python:2.7-jessie
WORKDIR /usr/src/app
COPY requirements.txt /usr/src/app
RUN pip install --no-cache-dir -r requirements.txt
COPY . /usr/src/app
CMD [ "python", "./startserver.py" ]
EXPOSE 5000

Output -
I get the same output if i run this locally or deploy the docker images I use the below command to tun this in local python main.py and for docker docker run -d -p 5000:5000 --name pythonapi pythonappid:v1

ExtDeprecationWarning: Importing flask.ext.jsonpify is deprecated, use flask_jsonpify instead.
  from flask.ext.jsonpify import jsonify
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

i hope i have included all the information necessary to help.

morningjoe
  • 11
  • 1

0 Answers0