# Docker with php5.6 ## 安裝 - 確認是否已安裝 Rosetta2 ``` softwareupdate --install-rosetta ``` - install docker ``` https://docs.docker.com/desktop/mac/apple-silicon/ ``` - [Docker LNMP (Nginx, PHP7/PHP5, MySQL, Redis)](https://golangrepo.com/repo/yeszao-dnmp-go-devops-tools) - how to fix error msg `no matching manifest for linux/arm64/v8 in the manifest list entries` - [link](https://chilunhuang.github.io/posts/8942/) - 編輯 docker-compose.yml 設定檔: - 隱藏 mysql - 開啟 php56 - 調整 host port 對應 container port ``` ports: - 9056:9000 ``` - 如果是用 docker內的 nginx 環境,可編輯 `/services/nginx/conf.d/localhost.conf` nginx 設定檔, 切換虛擬環境預設 php版本 ``` fastcgi_pass php56:9000; ``` - 進入docker 容器的方式: ``` docker exec -it {name} /bin/sh ``` - edit host nginx config (m1) ``` /opt/homebrew/etc/nginx server { listen 9005; server_name localhost; #charset koi8-r; access_log /var/logs/host.access.log; error_log /var/logs/service.error.log; location /api/ { proxy_pass http://localhost:9005/; } location / { root /Users/ming/projects/leishan_service/www/; try_files $uri $uri/ /index.php?$args /api.php?$args index index.php; chunked_transfer_encoding off; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root /Users/ming/projects/leishan_service/www; fastcgi_pass 127.0.0.1:9056; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /Users/ming/projects/leishan_service/www/$fastcgi_script_name; include fastcgi_params; } } ``` - composer install 如果出現以下訊息,執行下方指令忽略 >Your requirements could not be resolved to an installable set of packages. ``` composer install --ignore-platform-reqs ``` - ngrok - line message api - allen's docker compose config ``` # Use root/example as user/password credentials version: '3.7' services: project: container_name: php5.6 image: cs2ag/php5.6-devtest restart: always ports: - 9999:9000 volumes: - /Users/allenchen/projects/leishan_service:/Users/allenchen/projects/leishan_service ``` - nginx sample ``` #www server { listen 8080; server_name localhost; #charset koi8-r; access_log /Users/ming/log/nginx/host.access.log; error_log /Users/ming/log/nginx/host.error.log; location / { root /Users/ming/www/; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root /Users/ming/www/; fastcgi_pass 127.0.0.1:9056; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` - [記錄一次 docker:Primary script unknown" while reading response header from upstream](https://www.itread01.com/content/1545201554.html) - ```file not found``` issue ``` volumns: - /Users/ming/www:/Users/ming/www ``` ![](https://i.imgur.com/rksqlXG.png) Nginx: ``` location ~ \.php$ { root /Users/ming/www/; fastcgi_pass 127.0.0.1:9056; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /Users/ming/www/$fastcgi_script_name; include fastcgi_params; } ``` ![](https://i.imgur.com/qvM1aSL.jpg) - 掛載專案至主機中 - 執行 composer install, 安裝缺少的套件 # Mysql 5.7 - m1 mac 如安裝dnmp 專案中的 mysql service 時出現以下訊息: ``` mysql5 | runtime: failed to create new OS thread (have 2 already; errno=22) mysql5 | fatal error: newosproc ``` 請修改 dnmp專案之 docker-compose.yml 設定: ``` mysql5: # platform: linux/amd64 platform: linux/x86_64 ``` 並將 .env 檔中的 mysql 版本升級至 5.7.33 ``` # # MySQL5 # MYSQL5_VERSION=5.7.33 ``` 即可正常運作 # leishan_service 安裝 - nginx 使用 host 設定 - **php-fpm 路徑設定需使用容器內的路徑** ``` server { listen 9005; server_name localhost; #charset koi8-r; access_log /var/logs/host.access.log; error_log /var/logs/service.error.log; location /api/ { proxy_pass http://localhost:9005/; } location / { root /Users/ming/projects/leishan_service/www/; try_files $uri $uri/ /index.php?$args /api.php?$args index api.php; chunked_transfer_encoding off; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { root /home/projects/leishan_service/www; fastcgi_pass 127.0.0.1:9056; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } } ``` - mysql 使用 docker 容器 ``` mysql5: # platform: linux/amd64 platform: linux/x86_64 image: mysql:${MYSQL5_VERSION} container_name: mysql5 ports: - "${MYSQL5_HOST_PORT}:3306" volumes: - ${MYSQL5_CONF_FILE}:/etc/mysql/conf.d/mysql.cnf:ro - ${DATA_DIR}/mysql5:/var/lib/mysql/:rw # - /Users/ming/bin:/usr/bin restart: always networks: - default environment: MYSQL_ROOT_PASSWORD: "${MYSQL5_ROOT_PASSWORD}" TZ: "$TZ" ``` - 專案目錄需掛載至 php56 容器中 ``` php56: build: context: ./services/php args: PHP_VERSION: php:${PHP56_VERSION}-fpm-alpine CONTAINER_PACKAGE_URL: ${CONTAINER_PACKAGE_URL} PHP_EXTENSIONS: ${PHP56_EXTENSIONS} TZ: "$TZ" container_name: php56 ports: - 9056:9000 expose: - 9501 volumes: - ${SOURCE_DIR}:/www/:rw - ${PHP56_PHP_CONF_FILE}:/usr/local/etc/php/php.ini:ro - ${PHP56_FPM_CONF_FILE}:/usr/local/etc/php-fpm.d/www.conf:rw - ${PHP56_LOG_DIR}:/var/log/php - ${DATA_DIR}/composer:/tmp/composer - /Users/ming/projects/leishan_service:/home/projects/leishan_service restart: always cap_add: - SYS_PTRACE networks: - default ``` ## 啟用 - 啟動 dnmp docker 環境 ``` --https://pjchender.dev/devops/docker-command-line/ docker-compose up docker-compose ps # 列出該 docker-compose 中有哪些 services 在執行 docker-compose up --build # 對應到 docker build . 和 docker run <image-id> docker-compose up -d # 對應到類似 docker run <image-id>,-d 是在背景執行 docker-compose down docker run -it [image-id] # 根據 image 建立並執行 container docker run -p 8080:8080 <image-id> # port mapping localhost port:container port docker run -d redis # 讓該 container 在背景執行 ``` - 啟用 ngrok後的除錯 - Failed to complete tunnel connection ``` ```