![Docker 이미지 빌드에서 SSH를 사용한 Git 복제](https://rvso.com/image/1552393/Docker%20%EC%9D%B4%EB%AF%B8%EC%A7%80%20%EB%B9%8C%EB%93%9C%EC%97%90%EC%84%9C%20SSH%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%9C%20Git%20%EB%B3%B5%EC%A0%9C.png)
Docker 이미지를 구축 중이며 bitbucket에서 저장소를 복제하고 싶습니다.
`debian' 컨테이너를 만들고 단계별로 실행하면 모든 것이 잘 작동합니다. 그런데 이미지를 만들려고 하면 작동하지 않습니다.
bitbucket 설정에 키를 추가했습니다.
여기 나의Dockerfile
FROM debian:stretch
RUN apt-get update && apt-get -y upgrade && apt-get -y install nginx curl software-properties-common gnupg git
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN mkdir /backend
RUN npm install pm2 ts-node -g
WORKDIR /backend
RUN mkdir /root/.ssh
RUN echo -e "-----BEGIN RSA PRIVATE KEY-----\n(...)-----END RSA PRIVATE KEY-----" >> /root/.ssh/id_rsa
RUN chmod 400 /root/.ssh/id_rsa
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN git clone [email protected]:xxx/xxx.git
오류는 다음과 같습니다.
Cloning into 'xxx'...
Warning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
이 이미지가 제대로 작동하도록 하려면 어떻게 해야 합니까?
답변1
올바른 공개 키가 bitbucket에 있다고 확신하는 경우 (내 경험상) 대답은 거의 항상 .ssh 폴더 및 그 안에 있는 파일에 대한 권한입니다. 위에서는 해당 폴더와 그 안에 개인 키를 생성하고 권한을 업데이트하지 않는다는 것을 확인했습니다.
예상되는 권한
.ssh는 다음과 같아야 합니다.
drwx------ 2 user user 4096 Feb 6 11:18 .ssh
개인 키:
-rw------- 1 user user 1675 Feb 6 11:18 id_rsa
마지막으로 홈 디렉토리는 최소한 그룹이나 다른 사람이 쓸 수 없어야 합니다. 일반적으로 다음을 원합니다.
drwx------ 84 user user 16384 Feb 16 18:23 user
함께 모아서:
chmod go-w /root
chmod 700 /root/.ssh
chmod 600 /root/.ssh/id_rsa