0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerのコンテナ内のmysqlの日本語設定

Posted at

はじめに

Rails初学者ですが、docker+mysqlで開発したい!と思いdockerでrailsのプログラミングをしています。 イロイロ試行錯誤しながら、dockerコンテナを作っては消し、作っては消しを繰り返ししています。 (めちゃくちゃ面倒) その都度、dockerコンテナの日本語設定をしているので、改めてまとめてみました。

*この設定を行わないと、日本語が正しく表示されず????になります。
*多分都度都度でやらなくてもイロイロ方法があるんだと思う・・・ご教示いただければ幸いです。

*以下のqiitaを全面的に参考にさせていただいております。ありがとうございます。
https://qiita.com/maejima_f/items/4d5432aa471a9deaea7f

Dockerコンテナに入る


$ docker exec -it コンテナ名 bash

コンテナ内でlocaleの設定を確認する

root@XXXX :/# 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=

このlocaleの情報を日本かつUTF-8に変更するところからスタートです。
その前にコンテナ内をアップデートしたり、vimを入れ準備します。

root@XXXX :/# apt-get update
root@XXXX :/# apt-get install vim

*どちらも途中でインストールしますか?がでてきますのでyを入力し、コンテニューさせます。

2つを行ったあと、以下の設定を行います。

1.言語設定

*何度かenterを押しているとLocales to be generated:が出てくるので
 日本語の285. ja_JP.UTF-8 UTF-8 を入力しenterを押す(285は変わる可能性があります)

root@XXXX :/# dpkg-reconfigure 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               125. el_GR ISO-8859-7               249. gl_ES ISO-8859-1           373. pl_PL ISO-8859-2
  2. aa_DJ ISO-8859-1          126. el_GR.UTF-8 UTF-8              250. gl_ES.UTF-8 UTF-8          374. pl_PL.UTF-8 UTF-8
  3. aa_DJ.UTF-8 UTF-8         127. el_GR@euro ISO-8859-7          251. gl_ES@euro ISO-8859-15     375. ps_AF UTF-8
  4. aa_ER UTF-8               128. en_AG UTF-8                    252. gu_IN UTF-8                376. pt_BR ISO-8859-1
  5. aa_ER@saaho UTF-8         129. en_AU ISO-8859-1               253. gv_GB ISO-8859-1           377. pt_BR.UTF-8 UTF-8
  6. aa_ET UTF-8               130. en_AU.UTF-8 UTF-8              254. gv_GB.UTF-8 UTF-8          378. pt_PT ISO-8859-1
  7. af_ZA ISO-8859-1          131. en_BW ISO-8859-1               255. ha_NG UTF-8                379. pt_PT.UTF-8 UTF-8
  8. af_ZA.UTF-8 UTF-8         132. en_BW.UTF-8 UTF-8              256. hak_TW UTF-8               380. pt_PT@euro ISO-8859-15
  9. agr_PE UTF-8              133. en_CA ISO-8859-1               257. he_IL ISO-8859-8           381. quz_PE UTF-8
  10. ak_GH UTF-8              134. en_CA.UTF-8 UTF-8              258. he_IL.UTF-8 UTF-8          382. raj_IN UTF-8
  11. am_ET UTF-8              135. en_DK ISO-8859-1               259. hi_IN UTF-8                383. ro_RO ISO-8859-2
  12. an_ES ISO-8859-15        136. en_DK.ISO-8859-15 ISO-8859-15  260. hif_FJ UTF-8               384. ro_RO.UTF-8 UTF-8
  13. an_ES.UTF-8 UTF-8        137. en_DK.UTF-8 UTF-8              261. hne_IN UTF-8               385. ru_RU ISO-8859-5
[More] 

(略)

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

Locales to be generated: 285 #これは現在の日本語 UTF-8の設定番号です。

2.タイムゾーン設定

*まずは地域選択で、6のアジアを選択し、
*タイムゾーン選択で 79のTokyoを選択する

root@XXXX :/# dpkg-reconfigure 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   3. Antarctica  5. Arctic  7. Atlantic  9. Indian    11. SystemV  13. Etc
  2. America  4. Australia   6. Asia    8. Europe    10. Pacific  12. US
Geographic area: 6 #アジアを選択

Please select the city or region corresponding to your time zone.

  1. Aden      14. Beirut      27. Gaza         40. Karachi       53. Muscat        66. Riyadh         79. Tokyo
  2. Almaty    15. Bishkek     28. Harbin       41. Kashgar       54. Nicosia       67. Sakhalin       80. Tomsk
  3. Amman     16. Brunei      29. Hebron       42. Kathmandu     55. Novokuznetsk  68. Samarkand      81. Ujung_Pandang
  4. Anadyr    17. Chita       30. Ho_Chi_Minh  43. Khandyga      56. Novosibirsk   69. Seoul          82. Ulaanbaatar
  5. Aqtau     18. Choibalsan  31. Hong_Kong    44. Kolkata       57. Omsk          70. Shanghai       83. Urumqi
  6. Aqtobe    19. Chongqing   32. Hovd         45. Krasnoyarsk   58. Oral          71. Singapore      84. Ust-Nera
  7. Ashgabat  20. Colombo     33. Irkutsk      46. Kuala_Lumpur  59. Phnom_Penh    72. Srednekolymsk  85. Vientiane
  8. Atyrau    21. Damascus    34. Istanbul     47. Kuching       60. Pontianak     73. Taipei         86. Vladivostok
  9. Baghdad   22. Dhaka       35. Jakarta      48. Kuwait        61. Pyongyang     74. Tashkent       87. Yakutsk
  10. Bahrain  23. Dili        36. Jayapura     49. Macau         62. Qatar         75. Tbilisi        88. Yangon
  11. Baku     24. Dubai       37. Jerusalem    50. Magadan       63. Qostanay      76. Tehran         89. Yekaterinburg
  12. Bangkok  25. Dushanbe    38. Kabul        51. Makassar      64. Qyzylorda     77. Tel_Aviv       90. Yerevan
  13. Barnaul  26. Famagusta   39. Kamchatka    52. Manila        65. Rangoon       78. Thimphu

Time zone: 79 #Tokyoを選択

環境変数LANGへ設定をする
先ほどインストールしたvimで、.bashrcを編集し、
export...を追加する。

<vimでの編集方法>
vim ~/.bashrcで、vimが起動。
十字キーでファイルの一番下に移動して、「i」を押して入力モードへ
export〜を追記し、escを押してコマンドモードに戻る
「:wq」と入力して変更を保存する

root@XXXX :/# export LANG=ja_JP.UTF-8
root@XXXX :/# vim ~/.bashrc

もう一度 localeを見て見ると

root@XXXX :/# locale
LANG=ja_JP.UTF-8
LANGUAGE=
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC="ja_JP.UTF-8"
LC_TIME="ja_JP.UTF-8"
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY="ja_JP.UTF-8"
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER="ja_JP.UTF-8"
LC_NAME="ja_JP.UTF-8"
LC_ADDRESS="ja_JP.UTF-8"
LC_TELEPHONE="ja_JP.UTF-8"
LC_MEASUREMENT="ja_JP.UTF-8"
LC_IDENTIFICATION="ja_JP.UTF-8"
LC_ALL=

変更されてる!

プラスで、.inputrcというファイルを作成し、内容を追加しましょう。

root@XXXX :/# vim ~/.inputrc
# 以下の3行を.inputrcに追加する
set convert-meta off
set meta-flag on
set output-meta on

# 適用
root@XXXX :/# source ~/.inputrc

以下のようにすると、mysql内の設定も変わっているかと思います。
以上です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?