LoginSignup
1
1

More than 5 years have passed since last update.

DockerコンテナでPythonのWEBフレームワーク「responder」を起動する

Posted at

はじめに

responderはPythonのWebフレームワークです。何かすごいらしいです。詳細はresponder入門を見てください。今回はresponderをDockerコンテナ内で起動してみました。

Docker準備

FROM python

RUN pip install responder && \
    pip install starlette==0.8

pip install starlette==0.8をしないとModuleNotFoundError: No module named 'starlette.lifespan'になってしまうようです。詳細はhttps://github.com/kennethreitz/responder/issues/255 を見てください。

docker build -t responder .

Hello, World!

import responder

api = responder.API()

@api.route("/hello/{who}")
def hello_to(req, resp, *, who):
    resp.text = f"hello, {who}!"

if __name__ == '__main__':
    api.run(address= "0.0.0.0")

User Guides通りに、api.run()のまま実行すると「このページは動作していません」と表示されてしまいます。Dockerコンテナ内で起動する場合には、api.run(address="0.0.0.0")とする必要があります。

実行

docker run -it -p 5042:5042 responder /bin/bash

http://localhost:5042/hello/world にアクセスすると、「hello, world!」と表示されます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1