2003
[WEB] flask 프로젝트를 docker 컨테이너화 하기 본문
DOCKER 컨테이너화
1. requirement.txt 생성
pip freeze > requirements.txt
2. Dockerfile 작성
# Base image
FROM python:3.12
# Set working directory
WORKDIR /[working directory]
# Copy requirements.txt file
COPY requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy application files
COPY . .
# Set environment variables
ENV FLASK_APP=app.py
# Expose port
EXPOSE 5000
# Run the application
CMD ["python", "app.py"]
3. app.py 수정
app = Flask(__name__)
host_addr = "0.0.0.0"
host_port = 5000
###
if __name__ == "__main__":
app.run(host=host_addr,port=host_port)
4. docker image build
docker build -t [이미지 이름] .
5. docker 컨테이너 실행
docker run -it -p 5000:5000 [이미지 이름]
6. 해당 URL로 드가서 잘 실행되는지 확인하기
'개발' 카테고리의 다른 글
| [Linux] MYSQL, ORACLE DB, MSSQL 등 서비스 실행 명령어 (0) | 2024.02.19 |
|---|---|
| [Linux] ip 할당 수동/자동 변경 (0) | 2024.02.19 |
| [Oracle] CLI 에서 한글이 깨져 보일 때 해결 방법 (0) | 2024.02.15 |
| [ETC] Visual Studio Code 유용한 Extentions - Remote - SSH (0) | 2024.02.13 |
| [WEB] Python을 이용한 간단한 웹 서버 구축 (0) | 2024.02.13 |