ModuleNotFoundError:尝试进行docker-compose

时间:2018-09-07 20:53:52

标签: python docker

我刚刚开始玩Docker。我已经阅读了Dockers,并观看了一些教程视频。我正在尝试使用Python创建一个简单的表单,该表单将构建并使用Docker显示在我的本地主机上。我正在使用 烧瓶 wtforms 。我已经安装了pip flask,flask_wtf和wtforms,但是当我尝试使用sudo docker-compose up进行构建时,我不断收到错误ModuleNotFoundError: No module named 'wtforms'。我在这里已经阅读了许多其他类似的问题,但是没有一种解决方案适合我。我已经在下面复制了我正在使用的三个文件:

-api.py-

# docker test 

from flask import Flask, render_template, flash, request
from flask_restful import Resource, Api
from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField

app= Flask(__name__)
api= Api(app)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = '7d441f27d441f27567d441f2b6176a'
@app.route("/", methods=['GET', 'POST'])

class UserForm(Form):
    salutation= TextField('Salutation:', validators= [validators.required()])
    first_name= TextField('First Name:', validators= [validators.required()])
    last_name= TextField('Last Name:', validators= [validators.required()])

def welcome():
    form = UserForm(request.form)
    print(form.errors)
    if request.method == 'POST':
        salutation=request.form['salutation']
        first_name=request.form['first_name']
        last_name=request.form['last_name']
        print(salutation)
        print(first_name)
        print(last_name)

        if form.validate():
            flash('Welcome' + salutation + last_name)
        else:
            flash('Please fill in the required fields.')

api.add_resource(UserForm, '/')

if __name__ == '__main__':
    app.run(host= '0.0.0.0', port=80, debug=True)

-requirements.txt-

Flask==0.12
flask-restful==0.3.5
wtforms==2.2

-docker-compose.yml-

version: '2'
services:
  form-service:
    build: ./form
    volumes:
      - ./form:/usr/src/app
    ports:
      - 5001:80

-Dockerfile-

FROM python:3-onbuild
COPY . /usr/src/app
CMD ["python", "api.py"]

0 个答案:

没有答案