공공연히 개발하기 🧑‍💻/Back-end

[Docker] Image 빌드 시, 한 줄로 사용자 상호작용 방지하고 덜 귀찮기

공공연히 2024. 9. 1. 19:18

Table of Contents

1. Docker 빌드
    - 형식
    - 파일명 지정 
    - 파일명 생략 가능
2. 이미지 빌드 시 사용자 상호 작용
    - 상호작용 방지 방법

 

출처: Docker

1. Docker 빌드

작성된 Dockerfile로 Docker 이미지를 빌드한다

▶️  형식

docker build [OPTIONS] [PATH]

 
▶️  파일명 지정

docker build -t dgl-gpu -f Dockerfile.ci_gpu_cu11 .

-t : tag
-t옵션으로 이미지에 태그를 걸 수 있다.

ex) -tag graphs:1.0 과 같이 사용 가능


▶️  
파일명 생략 가능

Dockerfile이 있는 경로 + 파일명이 Dockerfile인 경우

docker build -t dgl-gpu .

기본값이 ./Dockerfile 이기 때문       

      

2.  이미지 빌드 시 사용자 상호 작용 (User interaction)

이미지 빌드 시 아래와 같은 사용자 선택 화면이 나오면 설치하기 번거롭다.
(골라줘야 돼서 귀찮)
특히 테스트 등으로 이미지 빌드가 잦을 경우,
매번 입력해줘야 해서 딴짓을 못한다.

Preconfiguring packages ...
Configuring tzdata
------------------

Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.

 1. Africa      4. Australia  7. Atlantic  10. Pacific  13. Etc
 2. America     5. Arctic     8. Europe    11. SystemV
 3. Antarctica  6. Asia       9. Indian    12. US
Geographic area:

...

          

⭐️  상호 작용 방지 방법

Dockerfile에 DEBIAN_FRONTEND=noninteractive 한 줄만 추가해주면 된다.

ex)

# CI docker GPU env
FROM nvidia/cuda:11.4.2-cudnn8-devel-ubuntu20.04

ARG DEBIAN_FRONTEND=noninteractive 

RUN apt-get update --fix-missing

...

         

이렇게 철벽쳐 준 뒤 실행하면 이제 빌드할 때 귀찮게 안 한다.