반응형
docker build 할때 간혹 느림, 혹은 아예 멈춤증상이 발생한내용을 해결한다.
증상
다음과 같은 나타난다.
docker build
명령어 혹은docker-compose build
명령어 시에 멈춤증상 혹은 엄청느림
아무리 기다려도 명령어가 끝나지 않거나, 아예 멈춘것같은 느낌이 든다.
해결하기
문제원인
레퍼런스문서(https://docs.docker.com/engine/reference/commandline/build/)를 보면 다음과 같은 내용이 나온다.
In most cases, it’s best to put each Dockerfile in an empty directory. Then, add to that directory only the files needed for building the Dockerfile. To increase the build’s performance, you can exclude files and directories by adding a .dockerignore file to that directory as well. For information on creating one, see the .dockerignore file.
즉, docker build
명령어를 칠때 Dockerfile
파일이 있는 폴더내의 모든 내용을 docker 를 만들기위해 임시디렉토리에 카피를 하게 된다. 때문에 Dockerfile
이 비어있지 않은 폴더의 용량이 클때는 docker build
명령어가 엄청~~ 느린것처럼 느껴지는것이다.
해결책 : .dockerignore 파일 이용하기
간혹 stack overflow 같은 곳에서의 해결책으로 답변하는것이.. 비어있는 폴더에서 Dockerfile
을 만들고 docker build
를 하라고 한다. 이런방법은 세련되지 않으므로 .dockerignore
파일을 이용하는 방법을 추천한다.
.dockerignore
파일은 간단하게 설명하면.. docker image 를 만들때 포함하지 않아야할 파일들을 명세하는 설정파일이라고 보면된다. 대부분의 .git
폴더나, 단순 저장 데이터를 적어주면된다.
즉, 간단하게 폴더내에 용량이 많은 파일 혹은 폴더들을 .dockerignore
파일에 적어주면된다.
문제 해결!!
반응형