1. Requirements.txt 생성

%%writefile requirements.txt
pandas
fsspec
numpy
matplotlib
scikit-learn
statsmodels
google-api-core
google-api-python-client
google-auth>=2.15.0
google-auth-httplib2
google-auth-oauthlib
google-cloud
google-cloud-aiplatform
google-cloud-bigquery
google-cloud-core
google-cloud-datastore
google-cloud-pipeline-components
google-cloud-storage
google-crc32c
google-resumable-media
googleapis-common-protos
kfp>=2.*
kfp-pipeline-spec
kfp-server-api
kubernetes
db-dtypes

 

2. Docker 파일 생성

%%writefile Dockerfile

FROM python:3.10
WORKDIR /
COPY requirements.txt /requirements.txt

RUN pip install --upgrade pip
RUN pip install -r requirements.txt
ENTRYPOINT [ "bash" ]
  • FROM: 파이썬 기본 버전이 기재된 base 이미지
  • WORKDIR: Container에서 작업 경로 설정
  • COPY: 도커실행폴더 기준으로 해당 파일 또는 폴더를 지정한 컨테이너 내부 위치로 복사
  • RUN: COMMEND 창에서 실행할 명령어 수행
  • ENTRYPOINT: 생성 시 실행되는 명령어

3. Docker Build Shell 스크립트 생성

%%writefile docker_build.sh
#!/bin/bash     
PROJECT_ID="프로젝트명"
REGION="리전명"
REPOSITORY="Artifact 레포지토리 이름"
IMAGE_TAG='이미지명'

docker build -t $REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE_TAG .
  • GCP Artifact Repository 내 지정된 Repository 장소에 IMAGE_TAG 이름으로 이미지 build 수행
  • 로컬에 이미지 생성

4. Docker Push Shell 스크립트 생성

%%writefile docker_push.sh
#!/bin/bash     
PROJECT_ID="프로젝트명"
REGION="리전명"
REPOSITORY="Artifact 레포지토리 이름"
IMAGE_TAG='이미지명'

####### artifact registry repository 생성 안했을 때, 진행하는 부분
# Create repository in the artifact registry
# gcloud beta artifacts repositories create $REPOSITORY \
#   --repository-format=docker \
#   --location=$REGION

# Configure Docker
gcloud auth configure-docker $REGION-docker.pkg.dev

# Push
docker push $REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY/$IMAGE_TAG
  • 로컬에 생성된 이미지를 Artifact Registry에 저장

+ Recent posts