update some content
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"articleSection" : "post",
|
||||
"name" : "[筆記] 修改 docker 容器內的時區 - Change Timezone in Docker",
|
||||
"headline" : "[筆記] 修改 docker 容器內的時區 - Change Timezone in Docker",
|
||||
"description" : "\x3cp\x3e最近一直在玩一些docker,不過老是會碰到歪果扔寫的東西,時區都不一致\x3c\/p\x3e\n\x3cp\x3e有的用 UTC,有的用localtime,就是沒碰到用 Asia\/Taipei 的\x26hellip;.\x3c\/p\x3e",
|
||||
"description" : "\u003cp\u003e最近一直在玩一些docker,不過老是會碰到歪果扔寫的東西,時區都不一致\u003c\/p\u003e\n\u003cp\u003e有的用 UTC,有的用localtime,就是沒碰到用 Asia\/Taipei 的\u0026hellip;.\u003c\/p\u003e",
|
||||
"inLanguage" : "en",
|
||||
"author" : "Eric Chang",
|
||||
"creator" : "Eric Chang",
|
||||
@@ -21,8 +21,8 @@
|
||||
"accountablePerson" : "Eric Chang",
|
||||
"copyrightHolder" : "Eric Chang",
|
||||
"copyrightYear" : "2019",
|
||||
"datePublished": "2019-05-21 17:25:15 \x2b0800 CST",
|
||||
"dateModified" : "2019-05-21 17:25:15 \x2b0800 CST",
|
||||
"datePublished": "2019-05-21 17:25:15 \u002b0800 CST",
|
||||
"dateModified" : "2019-05-21 17:25:15 \u002b0800 CST",
|
||||
"url" : "https:\/\/h.cowbay.org\/post\/change-timezone-in-docker\/",
|
||||
"wordCount" : "270",
|
||||
"image" : "https://h.cowbay.orghttps://h.cowbay.org/images/post-default-3.jpg"",
|
||||
@@ -45,9 +45,9 @@
|
||||
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
||||
|
||||
<link href="https://h.cowbay.org/css/style.css?v=1632901488" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/style.css?v=1634607506" rel="stylesheet" id="theme-stylesheet" type='text/css' media='all'>
|
||||
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1632901488" rel="stylesheet" type='text/css' media='all'>
|
||||
<link href="https://h.cowbay.org/css/custom.css?v=1634607506" rel="stylesheet" type='text/css' media='all'>
|
||||
<link rel="shortcut icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
|
||||
<link rel="icon" href="https://h.cowbay.org/img/favicon.ico" type="image/x-icon">
|
||||
|
||||
@@ -313,7 +313,7 @@ if (!doNotTrack) {
|
||||
<p>本來看了這篇 <a href="https://www.arthurtoday.com/2016/07/how-to-setup-docker-container-timezone-host.html">https://www.arthurtoday.com/2016/07/how-to-setup-docker-container-timezone-host.html</a></p>
|
||||
<p>想說來試試看好了</p>
|
||||
<p>不過呢,一開始依照這篇的說明,在docker-compose.yml 內加入</p>
|
||||
<pre><code>web:
|
||||
<pre tabindex="0"><code>web:
|
||||
image: jarischaefer/docker-librenms
|
||||
hostname: librenms
|
||||
ports:
|
||||
@@ -326,13 +326,13 @@ if (!doNotTrack) {
|
||||
- TZ="Asia/Taipei"
|
||||
</code></pre><p>重起之後沒作用 0rz</p>
|
||||
<p>於是我又加入了</p>
|
||||
<pre><code> volumes:
|
||||
<pre tabindex="0"><code> volumes:
|
||||
- /etc/hosts:/etc/hosts
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
- /etc/timezone:/etc/timezone:ro
|
||||
</code></pre><p>結果啟動直接報錯誤了..</p>
|
||||
<p>看一下 log</p>
|
||||
<pre><code>May 21 09:09:12 bbs012 syslog-ng[12]: syslog-ng starting up; version='3.13.2'
|
||||
<pre tabindex="0"><code>May 21 09:09:12 bbs012 syslog-ng[12]: syslog-ng starting up; version='3.13.2'
|
||||
*** Running /etc/my_init.d/librenms_100_cron...
|
||||
*** Running /etc/my_init.d/librenms_101_ssl...
|
||||
*** Running /etc/my_init.d/librenms_102_ipv6...
|
||||
@@ -343,7 +343,7 @@ if (!doNotTrack) {
|
||||
*** Killing all processes...
|
||||
</code></pre><p>所以這個檔案不能改成 ro ,不過如果不能唯獨,那啟動docker的時候應該會被蓋掉吧?</p>
|
||||
<p>先來看一下那個 librenms_103_timezone 在幹什麼好了</p>
|
||||
<pre><code>docker exec -it librenms_web_1 cat /etc/my_init.d/librenms_103_timezone
|
||||
<pre tabindex="0"><code>docker exec -it librenms_web_1 cat /etc/my_init.d/librenms_103_timezone
|
||||
#!/bin/bash -e
|
||||
|
||||
if [ -n "$TZ" ]; then
|
||||
@@ -361,23 +361,23 @@ fi
|
||||
</code></pre><p>OK ,這裡的確是用傳進來的 $TZ 在設定timezone 沒錯</p>
|
||||
<p>可是我前面已經改過 docker-compose.yml</p>
|
||||
<p>有把 TZ帶進來了啊?再來確認一下</p>
|
||||
<pre><code>docker exec -it librenms_web_1 cat /etc/timezone
|
||||
<pre tabindex="0"><code>docker exec -it librenms_web_1 cat /etc/timezone
|
||||
"Asia/Taipei"
|
||||
|
||||
</code></pre><p>咦,沒錯啊? 欸斗,等等,那兩個 "” 有點刺眼…</p>
|
||||
</code></pre><p>咦,沒錯啊? 欸斗,等等,那兩個 "" 有點刺眼…</p>
|
||||
<p>跟本機的比對一下看看</p>
|
||||
<pre><code>2019-05-21 17:36:20 [mini@s013 librenms]$ docker exec -it librenms_web_1 cat /etc/timezone
|
||||
<pre tabindex="0"><code>2019-05-21 17:36:20 [mini@s013 librenms]$ docker exec -it librenms_web_1 cat /etc/timezone
|
||||
"Asia/Taipei"
|
||||
2019-05-21 17:36:23 [mini@s013 librenms]$ cat /etc/timezone
|
||||
Asia/Taipei
|
||||
2019-05-21 17:37:10 [mini@s013 librenms]$
|
||||
</code></pre><p>嗯,的確,本機的格式的確不包含那兩個 "”</p>
|
||||
</code></pre><p>嗯,的確,本機的格式的確不包含那兩個 ""</p>
|
||||
<p>那就改掉再來試試看吧…改成底下這樣</p>
|
||||
<pre><code> environment:
|
||||
<pre tabindex="0"><code> environment:
|
||||
- TZ=Asia/Taipei
|
||||
|
||||
</code></pre><p>重起 docker ,然後確認時間看看</p>
|
||||
<pre><code>2019-05-21 17:39:00 [mini@s013 librenms]$ docker-compose down;docker-compose up -d
|
||||
<pre tabindex="0"><code>2019-05-21 17:39:00 [mini@s013 librenms]$ docker-compose down;docker-compose up -d
|
||||
Stopping librenms_web_1 ... done
|
||||
Stopping librenms_mysql_1 ... done
|
||||
Removing librenms_web_1 ... done
|
||||
@@ -392,7 +392,7 @@ Asia/Taipei
|
||||
Tue May 21 17:39:48 CST 2019
|
||||
2019-05-21 17:39:48 [mini@s013 librenms]$
|
||||
</code></pre><p>OK ,果然沒有問題了!</p>
|
||||
<p>雖然是小小的”” ,還是要特別注意啊!</p>
|
||||
<p>雖然是小小的"" ,還是要特別注意啊!</p>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
@@ -681,7 +681,7 @@ title="pinterest icon"></i>
|
||||
</div>
|
||||
<script src="https://h.cowbay.org/js/jquery.min.js"></script>
|
||||
<script src="https://h.cowbay.org/js/jquerymigrate.js"></script>
|
||||
<script src="https://h.cowbay.org/js/production.min.js?v=1632901488"></script>
|
||||
<script src="https://h.cowbay.org/js/production.min.js?v=1634607506"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user