Engineering/Docker

docker build 중 "ERROR: failed to solve: error from sender: context canceled" 오류 해결

산책散策 2024. 3. 26. 17:04
728x90

docker build 명령어가 어느 순간 (2024년 3월~) 부터 처음 보는 오류가 발생했다.

 

빌드 중간에 "context canceld" 라고 나오는데 도대체 무슨 일일까?

 => CANCELED [internal] load build context
 => => transferring context: 1.78MB
ERROR: failed to solve: error from sender: context canceled

 

최근에 docker desktop 버전을 최신(4.28.0)로 업그레이드했는데, 그 영향인가 싶어서 다운그레이드를 했으나 동일한 오류가 나온다.

 

결국 구글의 도움을 받아서 해결하게 되었는데, 어이없게도 최근에 사용하게된 gitlab copilot chatting plugin 영향인듯하다.

프로젝트 디렉토리에 보면 .idea/copilot 이라는 디렉토리가 있는데, 특정 파일이 문제를 일으키는거 같다. 

 

아래 링크에서 방법을 찾았다.

https://github.com/docker/for-win/issues/13812

 

Canceled: context cancelled while "load build context" · Issue #13812 · docker/for-win

Description Cannot run docker compose with building images (but I also have similar project that works fine). Definition in docker-compose.yml: services: app-c: build: context: . target: app-c Of c...

github.com

 

오늘 이글을 작성하는 3주전에 "taco-killchain" 이란 분이 해결책을 남겼는데, .dockerignore 파일을 생성하고 안에 copilot 디렉토리를 예외처리하면 된다. docker image 파일 생성할때 제외할 내용을 추가하는 거기 때문에, ".idea" 말고도 ".git/", "log/" 디렉토리를 추가해주자.

(위의 링크 해결방법에는 .idea 디렉토리에 .dockerignore 파일을 추가하라고 하는데, 이 방법으로 도저히 안되더라!)

 

 

그리고 나서 다시 docker build 를 해보면 정상적으로 동작한다.