반응형
● interactive mode 로 도커 이미지 실행.
아래 명령을 사용하여 우분투 이미지를 실행하여 현재 locale 을 확인한다.
현재 도커 레포지토리를 통해 배포되는 대부분의 우분투 이미지는 locale 설정이 안되어 있을것이다.
(외국 애들은 한글이나 일본어, 중국어 따윈 관심 없을테니...)
docker run -it [IMAGE] /bin/bash
[zany@dione ~]$ docker run -it -u root ubuntu:base /bin/bash
[root@510a1395b315 ~]# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=


[root@510a1395b315 ~]# locale -a
C
C.UTF-8
POSIX

[root@510a1395b315 ~]# ls /usr/share/i18n/locales/
ls: cannot access '/usr/share/i18n/locales/': No such file or directory
locale 명령을 입력해보면, POSIX 로 표기될 것이고
locale -a 명령으로 사용 가능한 locale 목록을 보면 위 결과와 같이 몇개 안나올 것이다.
/usr/share/i18n/locales 디렉토리는 존재하지도 않는다.

echo '한글' 명령으로 tty 에서 한글이 되는지 확인하지도 못한다.
echo '한글' 이라는 명령어 자체도 입력 못할테니...

● 우분투 패키지 매니저로 locales 설치
locale 이 있어야 설정을 하든 말든 할테니...
일단 우분투 패키지 매니저(apt-get)를 통해 locales 패키지를 설치하자 (아래 명령)
apt-get upgrade 는 OS 에 설치된 패키지를 업그레이드 할 것이니 필요치 않으면 빼도 무방하다.
apt-get clean && apt-get update && apt-get upgrade && apt-get install locales
[root@510a1395b315 ~]# apt-get clean && apt-get update && apt-get upgrade && apt-get install locales
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [51.1 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]

... 어쩌구 저쩌구 생략 ... 

Selecting previously unselected package locales.
(Reading database ... 13279 files and directories currently installed.)
Preparing to unpack .../locales_2.23-0ubuntu9_all.deb ...
Unpacking locales (2.23-0ubuntu9) ...
Setting up locales (2.23-0ubuntu9) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Generating locales (this might take a while)...
Generation complete.
정상적으로 처리되었으면, /usr/share/i18n/locales/ 디렉토리에 locale 파일들이 생겼을 것이다.
ls 명령으로 /usr/share/i18n/locales/ 디렉토리의 내용을 보자.
ls /usr/share/i18n/locales/
[root@510a1395b315 ~]# ls /usr/share/i18n/locales/
C            bs_BA           en_ZM       ga_IE@euro          li_BE         ps_AF             tk_TM
POSIX        byn_ER          en_ZW       gd_GB               li_NL         pt_BR             tl_PH
aa_DJ        ca_AD           eo          gez_ER              lij_IT        pt_PT             tn_ZA
aa_ER        ca_ES           eo_US       gez_ER@abegede      ln_CD         pt_PT@euro        tr_CY
aa_ER@saaho  ca_ES@euro      es_AR       gez_ET              lo_LA         quz_PE            tr_TR
aa_ET        ca_ES@valencia  es_BO       gez_ET@abegede      lt_LT         raj_IN            translit_circle
af_ZA        ca_FR           es_CL       gl_ES               lv_LV         ro_RO             translit_cjk_compat
ak_GH        ca_IT           es_CO       gl_ES@euro          lzh_TW        ru_RU             translit_cjk_variants
am_ET        ce_RU           es_CR       gu_IN               mag_IN        ru_UA             translit_combining
an_ES        ckb_IQ          es_CU       gv_GB               mai_IN        rw_RW             translit_compat
anp_IN       cmn_TW          es_DO       ha_NG               mg_MG         sa_IN             translit_font
ar_AE        crh_UA          es_EC       hak_TW              mhr_RU        sat_IN            translit_fraction
ar_BH        cs_CZ           es_ES       he_IL               mi_NZ         sc_IT             translit_hangul
ar_DZ        csb_PL          es_ES@euro  hi_IN               mk_MK         sd_IN             translit_narrow
... 생략 ...
apt-get install locales 명령시 자동으로 locale-gen 명령이 수행되지만,
/usr/share/i18n/locales 디렉토리가 아직 보이지 않으면 locale-gen 명령을 별도로 수행해보자.
locales 패키지를 설치하여도 사용 가능한 locale 을 확인해보면 아직 원하는 것이 나오지 않는다.
locale -a
[root@510a1395b315 ~]# locale -a
C
C.UTF-8
POSIX

● locale 생성 / 등록
localedef 명령을 이용하여 필요한 locale 을 컴파일해준다.
-i 옵션은 inputfile 을 의미하며
-f 옵션은 문자셋을 의미한다.
localedef 명령 후, locale -a 명령으로 사용 가능한 locale 을 확인해보면 새로 추가한 2개의 항목이 보일 것이다.
localedef -i ko_KR -f UTF-8 ko_KR.UTF-8
localedef -i en_US -f UTF-8 en_US.UTF-8
locale -a
[root@510a1395b315 ~]# localedef -i ko_KR -f UTF-8 ko_KR.UTF-8
[root@510a1395b315 ~]# localedef -i en_US -f UTF-8 en_US.UTF-8
[root@510a1395b315 ~]# locale -a
C
C.UTF-8
POSIX
en_US.utf8
ko_KR.utf8

● locale 관련 패키지 재설정 (optional)
dpkg-reconfigure 명령으로 locale 설정을 다시 해준다.
아래 명령어를 실행하면 2가지를 묻는다.
1. 어떤 locale 을 사용할 것이냐?
2. 시스템 환경을 위한 기본 locale 을 뭘로 할꺼냐?
dpkg-reconfigure locales
[root@510a1395b315 ~]# dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "ko_KR.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
Configuring locales
-------------------

Locales are a framework to switch between multiple languages and allow users to use their language, country, characters,
collation order, etc.

Please choose which locales to generate. UTF-8 locales should be chosen by default, particularly for new installations.
Other character sets may be useful for backwards compatibility with older systems and software.

  1. All locales                      162. es_CL ISO-8859-1               323. mni_IN UTF-8
  2. aa_DJ ISO-8859-1                 163. es_CL.UTF-8 UTF-8              324. mr_IN UTF-8
  3. aa_DJ.UTF-8 UTF-8                164. es_CO ISO-8859-1               325. ms_MY ISO-8859-1
  4. aa_ER UTF-8                      165. es_CO.UTF-8 UTF-8              326. ms_MY.UTF-8 UTF-8
  5. aa_ER@saaho UTF-8                166. es_CR ISO-8859-1               327. mt_MT ISO-8859-3
  6. aa_ET UTF-8                      167. es_CR.UTF-8 UTF-8              328. mt_MT.UTF-8 UTF-8
  7. af_ZA ISO-8859-1                 168. es_CU UTF-8                    329. my_MM UTF-8
  8. af_ZA.UTF-8 UTF-8                169. es_DO ISO-8859-1               330. nan_TW UTF-8
  9. ak_GH UTF-8                      170. es_DO.UTF-8 UTF-8              331. nan_TW@latin UTF-8
  10. am_ET UTF-8                     171. es_EC ISO-8859-1               332. nb_NO ISO-8859-1
  ... 생략 ...

(Enter the items you want to select, separated by spaces.)

Locales to be generated: 290

  ... 생략 ...

This will select the default language for the entire system. If this system is a multi-user system where not all users are
able to speak the default language, they will experience difficulties.

  1. None  2. C.UTF-8  3. ko_KR.UTF-8
Default locale for the system environment: 3
ko_KR.UTF-8 이 290 번 이어서 290 으로 입력 하였으나,
OS 버전에 따라 다를 수 있으니 목록에서 적절한 번호를 골라 입력한다.

● .bashrc 에 LANG 환경값 추가
LANG 환경값을 .bashrc 에 등록해준다.
export LANG=ko_KR.UTF-8

● 도커 커밋 후... 재실행.. 확인.
현재 도커를 커밋하고 종료 후 재실행하여 locale 이 정상적으로 적용되었는지 확인하자.
도커를 커밋하지 않으면 변경 내용이 이미지에 기록되지 않으니 꼭 커밋하고 재실행해서 확인하자.
docker commit -p [CONTAINER] [REPOSITORY[:TAG]]
[zany@dione ~]$ docker commit -p 510a1395b315 ubuntu:base
sha256:65afd6c09559b1001316c067b075e3a73c5aa02132752a9e184b0dedf2be2097
[root@a0610820dc88 ~]# locale
LANG=ko_KR.UTF-8
LANGUAGE=
LC_CTYPE="ko_KR.UTF-8"
LC_NUMERIC="ko_KR.UTF-8"
LC_TIME="ko_KR.UTF-8"
LC_COLLATE="ko_KR.UTF-8"
LC_MONETARY="ko_KR.UTF-8"
LC_MESSAGES="ko_KR.UTF-8"
LC_PAPER="ko_KR.UTF-8"
LC_NAME="ko_KR.UTF-8"
LC_ADDRESS="ko_KR.UTF-8"
LC_TELEPHONE="ko_KR.UTF-8"
LC_MEASUREMENT="ko_KR.UTF-8"
LC_IDENTIFICATION="ko_KR.UTF-8"
LC_ALL=
[root@a0610820dc88 ~]# echo '한글'
한글
[root@a0610820dc88 ~]#


반응형

'Program > Python' 카테고리의 다른 글

ubuntu Jupyter  (0) 2018.07.13
numpy axis  (0) 2018.07.13
file "/usr/bin/pip" line 9, in <module>  (0) 2018.07.03
[OpenCV] face detection  (0) 2018.06.28
[OpenCV] 영상 얼굴 인식 (face detection)  (0) 2018.06.28

+ Recent posts