Skip to content

Commit

Permalink
Add signal handler
Browse files Browse the repository at this point in the history
  • Loading branch information
takara9 committed May 20, 2024
1 parent 5881544 commit 40b348d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
42 changes: 13 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@
# 3.5.1 Pythonで開発するREST-APIサーバー
## イメージのビルドと実行

## イメージのビルド
docker build -t ex1:1.3 .
docker run --name ex1 --publish 9103:9100 --detach ex1:1.3

~~~
$ ls
Dockerfile README.md app.py
$ docker build -t ex1:1.0 .
~~~

## イメージの実行


~~~
docker run --name ex1 --publish 9100:9100 --detach ex1:1.0
~~~

## アクセス

~~~
curl http://localhost:9100/ping;echo
~~~
curl http://localhost:9102/ping;echo


## コンテナへ入る

~~~
docker exec -it ex1 bash
~~~


## イメージをレジストリへ登録

~~~
export CR_PAT=YOUR_TOKEN
export USERNAME=YOUR USERID
export USERNAME=YOUR USERID
echo $CR_PAT | docker login ghcr.io -u $USERNAME --password-stdin
docker tag ex1:1.0 ghcr.io/takara9/ex1:1.0
docker push ghcr.io/takara9/ex1:1.0
~~~
docker tag ex1:1.1 ghcr.io/takara9/ex1:1.1
docker push ghcr.io/takara9/ex1:1.1


## クリーンナップ

~~~
docker stop ex1
docker rm ex1
docker rmi ghcr.io/takara9/ex1:1.0
docker rmi ex1:1.0
~~~
docker rmi ghcr.io/takara9/ex1:1.1
docker rmi ex1:1.1



16 changes: 14 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import signal
import sys
from flask import Flask

app = Flask(__name__)
# シグナルを受けた時の処理
def handler(signum, frame):
# ここにアプリケーションの終了処理を書く
#
# コンテナ終了
sys.exit()

# シグナルSIGTERMを受けた時の処理先関数を定義
signal.signal(signal.SIGTERM, handler)

# Webサービス
app = Flask(__name__)
@app.route("/ping")
def hello_world():
def webservice1():
return "PONG!"

0 comments on commit 40b348d

Please sign in to comment.