๐Ÿšง

[Docker] ์ปจํ…Œ์ด๋„ˆ ํ•œ๊ธ€ ์ž…๋ ฅ ๋กœ์ผ€์ผ(locale) ์„ค์ •

purpplee 2021. 11. 24. 14:20

์–ธ์–ด ์„ค์ • ๊ด€๋ จ ๊ฒŒ์‹œ๋ฌผ ์ •๋ง ๋งŽ์•˜๋Š”๋ฐ... ๋‹ค ์‹คํŒจํ•˜๊ณ  ์„ฑ๊ณตํ•œ ๐Ÿ‘‰ 44BITS ๋‹˜์˜ ๊ฒŒ์‹œ๋ฌผ์„ ์ฐธ๊ณ ํ–ˆ๋‹ค.

 

๋„์ปค ์ปจํ…Œ์ด๋„ˆ ํ•œ๊ธ€ ์ž…๋ ฅ ์„ค์ •

๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋ฐฐ์‰ฌ์—์„œ ํ•œ๊ธ€์„ ์ž…๋ ฅํ•˜๋ฉด ์ž…๋ ฅ์ด ์•ˆ๋œ๋‹ค. ์ปจํ…Œ์ด๋„ˆ์˜ ๋กœ์ผ€์ผ ์„ค์ • ๋•Œ๋ฌธ์ด๋‹ค. ์ปจํ…Œ์ด๋„ˆ์˜ ๋กœ์ผ€์ผ ์„ค์ •๊ฐ’๊ณผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋กœ์ผ€์ผ์€ ์•„๋ž˜์ฒ˜๋Ÿผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

#ํ˜„์žฌ ๋กœ์ผ€์ผ ์„ค์ •
root@8c66d4754f83:/# locale
...
LC_ALL=

#์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋กœ์ผ€์ผ ํ™•์ธ
root@8c66d4754f83:/# locale -a
C
C.UTF-8
POSIX

 

ํ•œ๊ธ€์€ C.UTF-8 ์ด๋‚˜ ko_KR.UTF-8 ์„ ์ด์šฉํ•ด์•ผ ํ•œ๋‹ค. ํ˜„์žฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋กœ์ผ€์ผ์€ C.UTF-8 ์ด๋‹ˆ ์ด ๊ฐ’์„ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ ์‹œ ์˜ต์…˜์œผ๋กœ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

$ docker exec -e LC_ALL=C.UTF-8 ...

 

ko_KR.UTF-8 ์„ค์ •

๋งŒ์•ฝ ko_KR.UTF-8์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค. locales ํŒจํ‚ค์ง€๋ฅผ ์„ค์น˜ํ•˜๊ณ  locale-gen ๋ช…๋ น์–ด๋กœ ko_KR.UTF-8 ๋กœ์ผ€์ผ์„ ์ƒ์„ฑํ•œ๋‹ค. ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋กœ์ผ€์ผ์„ ํ™•์ธํ•ด๋ณด๋ฉด ์ถ”๊ฐ€๋˜์–ด ์žˆ์„ ๊ฒƒ์ด๋‹ค.

#ko_KR ๋กœ์ผ€์ผ ์„ค์น˜
root@8c66d4754f83:/# apt-get update
root@8c66d4754f83:/# apt-get install locales
root@8c66d4754f83:/# locale-gen ko_KR.UTF-8


#์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋กœ์ผ€์ผ ํ™•์ธ
root@8c66d4754f83:/# locale -a
...
ko_KR.utf8

 

์ปจํ…Œ์ด๋„ˆ์˜ LC_ALL ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ko_KR.utf8 ๋กœ ์„ค์ •ํ•˜๊ณ  ํ™•์ธํ•ด๋ณด์ž. ๋งŒ์•ฝ bash: warning: setlocale: LC_ALL: cannot change locale (ko_KR.utf8) ๊ฒฝ๊ณ ๊ฐ€ ๋œจ๋Š”๋ฐ ๋ฐ”๋€Œ์–ด ์žˆ๋‹ค๋ฉด ๋ฌด์‹œํ•ด๋„ ๋˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค...

#๋กœ์ผ€์ผ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ko_KR ๋กœ ์„ค์ • 
root@8c66d4754f83:/# export LC_ALL=ko_KR.utf8

#ํ˜„์žฌ ๋กœ์ผ€์ผ ์„ค์ • ํ™•์ธ
root@8c66d4754f83:/# locale
...
LC_ALL=ko_KR.utf8

 

๋ฐฐ์‰ฌ๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•ด ํ•œ๊ธ€ ์ž…๋ ฅ์ด ๋˜๋Š”์ง€ ํ™•์ธํ•ด๋ณธ๋‹ค.

root@8c66d4754f83:/# LC_ALL=ko_KR.UTF-8 bash
root@8c66d4754f83:/# ํ•œ๊ธ€์„ ์ž…๋ ฅํ•ด๋ณด์„ธ์š”~

 

์ดํ›„ ์•„๋ž˜ ์˜ต์…˜์„ ๋ถ™์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

$ docker exec -e LC_ALL=ko_KR.UTF-8 ...

 

์ด๋ฏธ์ง€๋กœ ๋นŒ๋“œํ•˜๊ธฐ

ko_KR ๋กœ์ผ€์ผ์ด ๋ฏธ๋ฆฌ ์„ค์ •๋˜์–ด ์žˆ๋Š” ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋ฐฐํฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜๋Œ€๋กœ ์ง„ํ–‰ํ•˜์ž. ์ปจํ…Œ์ด๋„ˆ ๋ฐฐ์‰ฌ๋Š” exit ๋กœ ์ข…๋ฃŒํ•˜๊ณ , ์ง€๊ธˆ๊นŒ์ง€ ์‹คํ–‰ํ–ˆ๋˜ ๋ช…๋ น์–ด๋ฅผ Dockerfile ๋กœ ๋งŒ๋“ ๋‹ค.

$ mkdir images
$ cd images
images $ vi Dockerfile

#์•„๋ž˜ ๋‚ด์šฉ ์ž‘์„ฑ
FROM [ํ˜„์žฌ image name]
RUN apt-get update && apt-get install -y locales
RUN locale-gen ko_KR.UTF-8
ENV LC_ALL ko_KR.UTF-8
~
~
~

 

์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ๋งŒ๋“  dockerfile์„ ์ด๋ฏธ์ง€๋กœ ๋นŒ๋“œํ•  ์ˆ˜ ์žˆ๋‹ค.

$ docker build -t [์‚ฌ์šฉํ•  image name] .

์ž˜ ๋งŒ๋“ค์–ด์กŒ๋Š”์ง€ ํ™•์ธํ•ด๋ณธ๋‹ค.

bora@boraui-MacBookPro images % docker images
REPOSITORY   TAG       IMAGE ID       CREATED              SIZE
๋ฐ”๊พผimage   latest    037531664395   About a minute ago   123MB
์›๋ž˜image      latest    e2278f24ac88   2 weeks ago          410MB

 

ํ•ด๋‹น ์ด๋ฏธ์ง€๋ฅผ ์ปจํ…Œ์ด๋„ˆ๋กœ ์ƒ์„ฑํ•˜๊ณ  ๋ฐฐ์‰ฌ๋ฅผ ์‹คํ–‰ํ•ด๋ณด์ž.

$ docker run -it ๋ฐ”๊พผimage bash
root@5a21a8cbbe26:/# ํ•œ๊ธ€์„ ์ž…๋ ฅํ•ด ๋ณด์„ธ์š”~

 

๋ฐ˜์‘ํ˜•