在構建 GitLab CI 流程時,我遇到了一個問題。 我在開發機上建立了 PHP 的 Docker Image,但在 Gitlab-CI Runner 運行 Image 時, 出現了 “standard_init_linux.go:219: exec user process caused: exec format error” 的錯誤。 這個錯誤表示容器內部執行的可執行文件格式不正確或無效。
進一步分析後,我意識到問題可能是由於容器映像與主機操作系統的處理器架構不兼容引起的。 由於我的筆電是基於 Apple M2 晶片的 Mac,它使用的是 ARM 架構,而我的 CI 使用的容器映像可能是針對 x86 架構設計的。
解決方法
Docker for Mac 提供了一個功能稱為「多架構建置(Buildx)」,它允許我們在具有不同處理器架構的環境中建立 Docker Image。 以下是在 Mac 上建立 x86 架構的 Docker Image 的步驟: 確保您已安裝 Docker for Mac,並確保 Docker 客戶端已啟用 Buildx 功能。 可以使用以下命令來檢查是否啟用了 Buildx:
The twelve-factor app stores config in environment variables (often shortened to env vars or env). Env vars are easy to change between deploys without changing any code; unlike config files, there is little chance of them being checked into the code repo accidentally; and unlike custom config files, or other config mechanisms such as Java System Properties, they are a language- and OS-agnostic standard.
另一個是 Php Laravel 的官方作法
Laravel utilizes the DotEnv PHP library. In a fresh Laravel installation, the root directory of your application will contain a .env.example file that defines many common environment variables. During the Laravel installation process, this file will automatically be copied to .env.