본문 바로가기
Server/centos

docker file 내에서 git 특정 branch 클론하고 싶을 때

by 유주원 2023. 1. 3.

docker file 작성 중 github으로부터 특정 소스를 클론해야 하는 작업이 필요했다.

그래서 아래와 같이 작성.

 

FROM python:3.7-slim 

RUN mkdir -p /app 
WORKDIR /app 
RUN apt-get update 
RUN apt-get -y install git 
RUN git clone https://github.com/test.git 
WORKDIR /app/test 
RUN git checkout feature_1
RUN pip install --upgrade pip 
RUN pip install -r requirements.txt 
CMD [ "python", "test.py"]

 

하지만 위와 같이 실행시키니깐 git checkout 하는 부분에서 아래와 같은 에러가 발생한다.

 

error: pathspec 'feature_1' did not match any file(s) known to git

 

음 로컬 터미널에서는 잘 동작되는데 왜 안되지... 

그래서 이번에는 아예 git에서 clone 시 특정 브랜치를 명시하고 가져와 보기로 했다.

 

git clone 라인을 아래와 같이 수정하고 git checkout 라인을 삭제함.

 

RUN git clone -b feature_1 --single-branch https://github.com/test.git

 

오 잘 동작된다!!!