{"id":1716,"date":"2024-09-09T12:20:02","date_gmt":"2024-09-09T04:20:02","guid":{"rendered":"https:\/\/www.strongd.net\/?p=1716"},"modified":"2024-09-09T12:20:02","modified_gmt":"2024-09-09T04:20:02","slug":"docker-timezone-settings","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=1716","title":{"rendered":"Docker Timezone Settings"},"content":{"rendered":"<h1><span>\u3010Notes\u3011Docker Timezone Settings<\/span><\/h1>\n<p><span>If we want to\u00a0<\/span><code>Docker<\/code><span>set\u00a0<\/span><code>host<\/code><span>the same time zone internally, how should we set it?<\/span><\/p>\n<h2 id=\"Quick-Start\"><span>Quick Start<\/span><\/h2>\n<p><span>Many people on the Internet said that\u00a0<\/span><code>container<\/code><span>you can add the following command at startup:<\/span><\/p>\n<ul>\n<li><span>Method 1:<\/span><br \/>\n<blockquote><p><span>-v \/etc\/localtime:\/etc\/localtime:ro<\/span><\/p><\/blockquote>\n<\/li>\n<li><span>Method 2:<\/span><br \/>\n<blockquote><p><span>-and \u201cTZ=Asia\/Taipei\u201d<\/span><\/p><\/blockquote>\n<\/li>\n<\/ul>\n<p><span>But sometimes it works, and sometimes it doesn&#8217;t work. Why? It depends on what you use<\/span><code>docker image<\/code><\/p>\n<h3 id=\"\u4f7f\u7528-alpine-\u7684\u7248\u672c\"><span>Use\u00a0<\/span><code>alpine<\/code><span>the version<\/span><\/h3>\n<h4 id=\"dockerfile\"><span>dockerfile<\/span><\/h4>\n<div class=\"gitlab-embed-snippets\">\n<div class=\"js-file-title file-title-flex-parent\">\n<div class=\"file-header-content\">\u00a0<strong class=\"file-title-name\"><a class=\"gitlab-embedded-snippets-title\" href=\"https:\/\/gitlab.com\/greddyblogs\/greddyblogs.gitlab.io\/-\/snippets\/1935075\" target=\"_blank\" rel=\"noopener noreferrer\"><span>dockerfile\u00a0<\/span><\/a><\/strong><small><span>364 B\u00a0<\/span><\/small><a class=\"gitlab-logo-wrapper\" title=\"View on GitLab\" href=\"https:\/\/gitlab.com\/greddyblogs\/greddyblogs.gitlab.io\/-\/snippets\/1935075\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"gitlab-logo\" src=\"https:\/\/gitlab.com\/assets\/ext_snippet_icons\/logo-88d040ec5541207676259c7d6dd92345e719e117099a26d3a1361ade5bbd2b9c.svg\" alt=\"GitLab logo\" \/><\/a><\/div>\n<div class=\"file-actions gl-hidden sm:gl-block\">\n<div class=\"btn-group\" role=\"group\"><\/div>\n<\/div>\n<\/div>\n<figure class=\"file-holder snippet-file-content\" aria-label=\"Code snippet\">\n<div class=\"blob-viewer\" data-path=\"dockerfile\" data-type=\"simple\">\n<div class=\"file-content code js-syntax-highlight\">\n<div class=\"line-numbers\"><span class=\"diff-line-num\"><span>1<\/span><\/span><span class=\"diff-line-num\"><span>2<\/span><\/span><span class=\"diff-line-num\"><span>3<\/span><\/span><span class=\"diff-line-num\"><span>4<\/span><\/span><span class=\"diff-line-num\"><span>5<\/span><\/span><span class=\"diff-line-num\"><span>6<\/span><\/span><span class=\"diff-line-num\"><span>7<\/span><\/span><span class=\"diff-line-num\"><span>8<\/span><\/span><span class=\"diff-line-num\"><span>9<\/span><\/span><span class=\"diff-line-num\"><span>10<\/span><\/span><span class=\"diff-line-num\"><span>11<\/span><\/span><span class=\"diff-line-num\"><span>12<\/span><\/span><span class=\"diff-line-num\"><span>13<\/span><\/span><\/div>\n<div class=\"blob-content\" data-blob-id=\"104b7e64bf5870909d4819f8f90f2c626a21510a\">\n<pre class=\"code highlight\"><code><span id=\"LC1\" class=\"line\" lang=\"docker\"><span class=\"k\">FROM<\/span><span class=\"s\"> openjdk:12-alpine<\/span><\/span>\r\n<span id=\"LC2\" class=\"line\" lang=\"docker\"><span class=\"k\">VOLUME<\/span><span class=\"s\"> \/tmp<\/span><\/span>\r\n<span id=\"LC3\" class=\"line\" lang=\"docker\"><\/span>\r\n<span id=\"LC4\" class=\"line\" lang=\"docker\"><span class=\"k\">RUN <\/span>apk update <span class=\"o\">&amp;&amp;<\/span> <span class=\"se\">\\<\/span><\/span>\r\n<span id=\"LC5\" class=\"line\" lang=\"docker\">    apk add <span class=\"nt\">-U<\/span> tzdata<\/span>\r\n<span id=\"LC6\" class=\"line\" lang=\"docker\"><\/span>\r\n<span id=\"LC7\" class=\"line\" lang=\"docker\"><span class=\"k\">ADD<\/span><span class=\"s\"> build\/libs\/sb-crawler-0.0.1-SNAPSHOT.jar app.jar<\/span><\/span>\r\n<span id=\"LC8\" class=\"line\" lang=\"docker\"><span class=\"k\">RUN <\/span>sh <span class=\"nt\">-c<\/span> <span class=\"s1\">'touch \/app.jar'<\/span><\/span>\r\n<span id=\"LC9\" class=\"line\" lang=\"docker\"><\/span>\r\n<span id=\"LC10\" class=\"line\" lang=\"docker\"><span class=\"k\">EXPOSE<\/span><span class=\"s\"> 6565<\/span><\/span>\r\n<span id=\"LC11\" class=\"line\" lang=\"docker\"><span class=\"k\">ENV<\/span><span class=\"s\"> JAVA_OPTS=\"\"<\/span><\/span>\r\n<span id=\"LC12\" class=\"line\" lang=\"docker\"><span class=\"k\">ENV<\/span><span class=\"s\"> SPRING_PROFILES_ACTIVE=\"\"<\/span><\/span>\r\n<span id=\"LC13\" class=\"line\" lang=\"docker\"><span class=\"k\">ENTRYPOINT<\/span><span class=\"s\"> [ \"sh\", \"-c\", \"java $JAVA_OPTS -Djava.security.egd=file:\/dev\/urandom -Dspring.profiles.active=$SPRING_PROFILES_ACTIVE -jar \/app.jar\" ]<\/span><\/span><\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<\/div>\n<ul>\n<li><span>We\u00a0<\/span><code>dockerfile<\/code><span>added the installation\u00a0<\/span><code>tzdata<\/code><span>instructions in<\/span><\/li>\n<\/ul>\n<figure class=\"highlight plain\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre><span class=\"line\"><span>RUN apk update &amp;&amp; \\<\/span><\/span>\r\n<span class=\"line\"><span>    apk add -U tzdata<\/span><\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h4 id=\"\u555f\u52d5\u6307\u4ee4\"><span>Start command<\/span><\/h4>\n<ul>\n<li><span>Add to<\/span><code>-v \/etc\/localtime:\/etc\/localtime:ro<\/code><\/li>\n<\/ul>\n<figure class=\"highlight plain\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre><span class=\"line\"><span>docker run --name sb-crawler -d -h sb-crawler -p 8081:8081 -e SPRING_PROFILES_ACTIVE=prod -v \/home\/ec2-user\/log\/sb-crawler:\/log -v \/etc\/localtime:\/etc\/localtime:ro registry.gitlab.com\/sportsbook1\/sb-crawler:$CI_COMMIT_SHORT_SHA<\/span><\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<h3 id=\"\u4f7f\u7528\u975e-alpine-\u7684\u7248\u672c\"><span>Use\u00a0<\/span><code>alpine<\/code><span>a non-<\/span><\/h3>\n<p><span>The disadvantage is that it is\u00a0<\/span><code>alpine<\/code><span>much larger than the previous version and takes more time (push image)<\/span><\/p>\n<h4 id=\"dockerfile-1\"><span>dockerfile<\/span><\/h4>\n<ul>\n<li><span>Used\u00a0<\/span><code>image<\/code><span>for<\/span><code>openjdk:12<\/code><\/li>\n<\/ul>\n<h4 id=\"\u555f\u52d5\u6307\u4ee4-1\"><span>Start command<\/span><\/h4>\n<ul>\n<li><span>Add to<\/span><code>-e \"TZ=Asia\/Taipei\"<\/code><\/li>\n<\/ul>\n<p><span>That\u2019s it for today\u2019s notes. If you have any questions, let me know!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3010Notes\u3011Docker Timezone Settings If we want to\u00a0Dockerset\u00a0hostthe same time zone internally, how should we set it? Quick Start Many people on the Internet said that\u00a0containeryou can add the following command at startup: Method 1: -v \/etc\/localtime:\/etc\/localtime:ro Method 2: -and \u201cTZ=Asia\/Taipei\u201d But sometimes it works, and sometimes it doesn&#8217;t work. Why? It depends on what you &hellip; <a href=\"https:\/\/www.strongd.net\/?p=1716\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Docker Timezone Settings<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-1716","post","type-post","status-publish","format-gallery","hentry","category-20","post_format-post-format-gallery"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1716","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1716"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1716\/revisions"}],"predecessor-version":[{"id":1717,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/1716\/revisions\/1717"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1716"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1716"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1716"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}