差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

下次修改
前次修改
tech:php_docker_images [2021/10/20 18:50] – 建立 jonathantech:php_docker_images [2023/11/20 17:17] (目前版本) – [參考網址] jonathan
行 29: 行 29:
 ===== 改成 Dockerfile 安裝方式 ===== ===== 改成 Dockerfile 安裝方式 =====
   * 環境改變項目:   * 環境改變項目:
-    * php 改用 7.1 -> docker hub php:7.1-cli (OS:debian 10+    * php 改用 7.1 -> docker hub php:7.1-cli (OS:debian 10)
     * 改用 git repo     * 改用 git repo
     * 程式碼修改     * 程式碼修改
行 44: 行 44:
         unzip \         unzip \
         gnupg         gnupg
 +
 +# Set timezone
 +ENV TZ=Asia/Taipei
 +RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
  
 # Add PostgreSQL repository # Add PostgreSQL repository
行 90: 行 94:
 # install php repo # install php repo
 # cd /root && git clone https://192.168.1.31/root/erptools_googlesheet.git # cd /root && git clone https://192.168.1.31/root/erptools_googlesheet.git
-# cp -f /root/auto-data-updater/app/* /root/googlesheet/+# cp -f /root/erptools_googlesheet/app/* /root/googlesheet/
  
 +COPY app /root/googlesheet
 WORKDIR /root/googlesheet WORKDIR /root/googlesheet
 ENTRYPOINT ["php", "db-googlesheet.php"] ENTRYPOINT ["php", "db-googlesheet.php"]
 +</file>
 +  * db-googlesheet.php 內
 +    * 增加依據環境變數 TZ 的值來設定時區 <file>
 +:
 +require_once __DIR__ . '/vendor/autoload.php';
 +if (isset($_ENV["TZ"])) {
 + date_default_timezone_set($_ENV["TZ"]);
 +}
 +:
 +</file>
 +    * 依據環境變數來設定原本設定檔案的參數 <file>
 +:
 + // 判別環境變數是否有定義 DB_ID / DB_SERVER / DB_NAME / DB_USER / DB_PASSWD
 + $db_id = $_ENV["DB_ID"];
 + if ($db_id == $t_DB_ID) {
 + $db_server = $_ENV["DB_SERVER"];
 + $db_port = $_ENV["DB_PORT"];
 + $db_name = $_ENV["DB_NAME"];
 + $db_user = $_ENV["DB_USER"];
 + $db_passwd = $_ENV["DB_PASSWD"];
 + }
 + else {
 + print("The source database connection information (DB_ID, DB_SERVER, DB_NAME, DB_USER, DB_PASSWD) should be defined in the environment variables!\n");
 + exit;
 + }
 +:
 </file> </file>
   * 建立出的 docker image 為 tryweb/db-googlesheet:latest   * 建立出的 docker image 為 tryweb/db-googlesheet:latest
行 108: 行 139:
 ===== 參考網址 ===== ===== 參考網址 =====
   * https://github.com/merorafael/docker-php-cli/blob/master/7.1/Dockerfile   * https://github.com/merorafael/docker-php-cli/blob/master/7.1/Dockerfile
 +  * https://docs.docker.com/develop/develop-images/dockerfile_best-practices/
  
-{{tag>docker k8s}}+{{tag>docker k8s php}}
  
  • tech/php_docker_images.1634727013.txt.gz
  • 上一次變更: 2021/10/20 18:50
  • jonathan