Docker容器中没有模块错误请求

时间:2019-10-17 05:37:24

标签: python docker kubernetes

在Kubernetes容器上出现错误,即使我使用pip安装了模块也测试了多个Docker映像,也没有名为“ requests”的模块。

Docker文件:-

FROM jfloff/alpine-python:2.7


MAINTAINER "Gaurav Agnihotri"

#choosing /usr/src/app as working directory
WORKDIR /usr/src/app

# Mentioned python module name to run application
COPY requirements.txt ./

RUN pip install --no-cache-dir -r requirements.txt
RUN pip install requests==2.7.0

# Exposing applicaiton on 80 so that it can be accessible on 80
EXPOSE 80

#Copying code to working directory
COPY . .

#Making default entry as python will launch api.py
CMD [ "python", "app-1.py" ]

app-1.py

#!/usr/bin/env python
import random
import requests
from flask import Flask, request, jsonify

app = Flask(__name__)
@app.route('/api', methods=['POST'])
def api():
    user_data = request.get_json()
    data = user_data['message']
    r = requests.post('http://localhost:5000/reverse', json={'message': data })
    json_resp = r.json()
    a = random.uniform(0, 10)
    return jsonify({"rand": a, "message": json_resp.get("message")})
if __name__ == "__main__":

1 个答案:

答案 0 :(得分:0)

尝试一下,希望对您有所帮助。

Dockerfile:

A = {"first"}
B = {"second"}
C = A | B

class Custom(tuple):
    def __new__(self, pair, **metadata):
        return super(Custom, self).__new__(self,tuple(pair))
    def __init__(self, pair, **metadata):
        self.pair = tuple(pair)
        self.metadata = metadata

pair_1 = Custom(["A","B"])
pair_2 = Custom(["B","C"])
pair_1 | pair_2