본문 바로가기

개발

docker base image Debian 과 alpine - 효율적인 도커 이미지

도커를 사용하면 배포를 하기 위해 리눅스 베이스 이미지를 만든다. 

이때 사용하는 리눅스에 버전을 사용 할때 이미지를 고르는 기준은 무엇일까

 

도커 이미지 사이즈는 빌드와 배포 시간에 많은 영향을 주고, 쿠버네티스와 같은 컨테이너 스케쥴링 솔루션의 경우 

도커 이미지가 디스크 공간을 잡아 먹기 때문에, 작은 컨테이너가 여러모로 이점이 많다. 

베이스 이미지를 최적화하면 빌드와 배포 시간을 단축할 수 있다!! 

빌드 시간과 배포 시간 단축은 생산성 향상!!! 

 

알파인 리눅스는 가볍고 간단하고 보안성을 목적으로 개발한 리눅스 배포판이다.

데비안은 자유 오픈 소스 소프트웨어이고 랩톱, 데스크톱 및 서버를 비롯한 광범위한 장치를 위한 운영 체제이다데비안 10.9  2021년 3월 27일에 나왔고  2024 까지 lts 를 지원한다.

 

Debian -- List of sections in "buster"

List of sections in "buster" Administration Utilities Utilities to administer system resources, manage user accounts, etc. Mono/CLI Everything about Mono and the Common Language Infrastructure. Communication Programs Software to use your modem in the old f

packages.debian.org

 

자바 컨테이너를 만들때, 컴파일러가 포함된 JDK 환경을 사용하는데 자바 런타임은 JDK 없이 JRE 만 있어도 충분하다.

but 쓰레드 덤프 때문에 jdk로 하는 경우도 있다. 클라우드 상황에 따라 쓰레드 덤프가 떠야 할 수도 있는데

이때는 jdk 가 포함된 이미지를 사용하는게 좋다.

 

open jdk 에서 제공하는 jre slim buster 용량을 보면 67메가인것을 확인 할 수 있다.

 

jre alpine 용량은 55메가 

 

알파인과 데비안 둘 다 slim 말고 다른것들로 테스트를 해봤는데 

눈에 띄는 다른 점을 발견하지 못했다. 

권장 사항으로 작은 용량의 베이스 이미지가 쓰이는것이 추천된다.

 


sudo docker run -it openjdk:8-jdk-slim-buster /bin/bash

debian:<suite>-slim

These tags are an experiment in providing a slimmer base (removing some extra files that are normally not necessary within containers, such as man pages and documentation), and are definitely subject to change.

See the debuerreotype-slimify script (debuerreotype linked above) for more details about what gets removed during the "slimification" process.


root@98ea810e59f0:/# apt-get install git

Reading package lists... Done

Building dependency tree

Reading state information... Done

E: Unable to locate package git

--> 

This is happening because the apt repository is not yet updated, it is common practice to clean your apt repositories and tmp files after creating an image, which your base image is probably doing. To fix this, you are going to want to run apt-get update prior to installing git, it is good practice to combine the update and install command at the same time to bust cache on the update if the install line changes:

RUN apt-get update && apt-get install -y git

-> (-y) 모든 대답에 예를 선택

root@98ea810e59f0:/# apt-get install git


$ docker pull ${CI_REGISTRY_IMAGE}:latest || true

할때 에러 나면 



체크 





"logger_name":"com.zaxxer.hikari.pool.HikariPool","thread_name":"main","level":"ERROR","level_value":40000,"stack_trace":"java.sql.SQLException: ORA-00604: error occurred at recursive SQL level 1\nORA-01882: timezone region not found\n\n\tat oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)\n\tat 

--> run.sh에 -Doracle.jdbc.timezoneAsRegion=false \ 추가 
base 이미지를 만들때 타임존을 utc, asia/seoul 둘 다 바꿔도 오라클 접속시 에러남. 
리눅스 exec로 들어가서 date 찍어봐도 kst, utc로 각각 잘 나왔는데 두경우 다 에러.


rm -f /etc/localtime && \
ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime && \



알파인을 사용 해야 하는 3가지 이유 

 

The 3 Biggest Wins When Using Alpine as a Base Docker Image

If you want to shrink your Docker images, have your services start faster and be more secure then try Alpine out.

nickjanetakis.com

반응형