-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |