반응형
1. Dockerfile 준비
# Base Image는 miniconda3
FROM continuumio/miniconda3
# 필수 설치요소들 설치
RUN apt-get update && apt-get install -y build-essential cmake gcc vim wget \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip setuptools wheel
RUN pip install pandas numpy cvxpy cvxopt matplotlib pymysql sqlalchemy \
flask flask-restful flask_cors Flask-WTF jupyter gevent gunicorn
# Jupyter Notebook의 Terminal 기본 Setting을 bash shell로 지정. (아니라면 일반 쉘 terminal로 지정 됨)
c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash']}" >> /root/.jupyter/jupyter_notebook_config.py
# RUN jupyter notebook --generate-config
# RUN echo "c.NotebookApp.password_required=True" >> /root/.jupyter/jupyter_notebook_config.py
# RUN echo "c.NotebookApp.password=themostjh" >> /root/.jupyter/jupyter_notebook_config.py
# password 암호화해서 Setting
# RUN echo "\
# from IPython.lib import passwd \n\
# password = passwd('Juhyeon') \n\
# c.NotebookApp.password = password \n\
# c.NotebookApp.terminado_settings = {'shell_command': ['/bin/bash']}" >> /root/.jupyter/jupyter_notebook_config.py
WORKDIR /usr/local/app
COPY ./ /usr/local/app/
ENTRYPOINT ["sh", "entrypoint.sh"]
2. Dockerfile Build
$ docker build -t juhyeon/flaskapi:v0.1 .
출처 : https://sseongju1.tistory.com/19
3. Docker Run
$ docker run -it --rm -p 8889:8889 -p 8890:8890 -v "/home/jh:/home/jh" jh/flaskapi:v0.1
4. Jupyter Run
# jupyter notebook --allow-root(루트권한허용) --no-browser(브라우저창 안띄움) --ip=*(모든대역ip허용) --port=8989 (port할당)
root@8542f86e82be:/# jupyter notebook --allow-root --no-browser --ip=* --port=8989
앞서 Build시 비밀번호를 설정했다면 비밀번호를 입력 후 접속. 그렇지 않았다면 Jupyter Notebook 띄울 시 생성된 token을 입력하여 접속 가능하다.
5. flask API 테스트
# test.py
from flask import Flask
from flask import request
from flask import render_template
web_gui = Flask(__name__)
@web_gui.route('/')
def hello_fnc():
return 'Hello'
@web_gui.route("/page", methods = ["GET", "POST"])
def page_fnc():
if request.method == "POST":
return 'POST received'
else:
return render_template("page.html")
if __name__ == "__main__":
web_gui.run(debug=True, host='0.0.0.0', port=8890)
root@8542f86e82be:/jh/flaskapi_test$ python test.py
* Serving Flask app 'test' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://x.x.x.x:8890/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: xxx-xxx-xxx
테스트 성공
끄읏 (Request 및 Response로 내용 채워나갈 예정)
반응형
'Development > Docker' 카테고리의 다른 글
[Docker] WARNING: Retrying after connection broken by NewConnectionError 문제 해결 (0) | 2022.05.04 |
---|---|
[Linux & Docker] VS Code로 Docker Container에 접속하기 (0) | 2022.02.10 |
[Docker] Container 에서 Jupyter Notebook 실행 시 비밀번호 설정 (0) | 2021.12.27 |
[Docker] Dockerfile Build 시 특정 파일에 echo로 multiline 추가하기 (0) | 2021.12.27 |
[Docker] Build 후 레포지토리:태그 가 none 인경우(Dangling Images) (0) | 2021.12.16 |
댓글