DNS Resolution Problem at start on Apple M2

最近把 Spring Boot 升級到 3.2.1 後、莫名的遇到了以下的警告:

Unable to load io.netty.resolver.dns.macos.MacOSDnsServerAddressStreamProvider, fallback to system defaults. This may result in incorrect DNS resolutions on MacOS. Check whether you have a dependency on 'io.netty:netty-resolver-dns-native-macos'. Use DEBUG level to see the full stack: java.lang.UnsatisfiedLinkError: failed to load the required native library

經查:應該是因為在使用M晶片的 macOS 上缺了系統需要的 Library。

在 pom.xml 加入以下依賴即可解決:

<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
        </dependency>

[Docker]The requested image’s platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested

在新的 M2 pro 上依循著之前的方法製作了 Docker Containter ,卻在 Synology NAS 上的 Docker 上要復原時發生了以下的錯誤訊息:

The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested.

經查詢後得知:在 M1/M2 中 build 出來的 Containter 是只能在它自己的環境中(linux/arm64/v8)執行;所以當導到其他的架構時、因為 amd64v8 和原本的 amd64 for x86 指令集不同時就會出現錯誤;雖然 Dcoker 構建出來的容器是可以在大多數操作系統上運作的、但⋯⋯需要特別注意的是:Docker 容器的架構類型仍需和 Host 的操作系統相對應。例:Ubuntu 是 x86 的、那麼 Docker 也必需是 x86 的。

最簡單的解決方法即是在 MBP M2 中 build 的時候使用 buildx 並加入 –platform linux/amd64 即可、如下:

docker buildx build --platform=linux/amd64 -t testwebyserp .

[Update] How to install MSSQL Server on Mac M2 using Docker

近期將電腦升級為 Mac M2 ,之前文章中所使用 2019 & 2017 的版本因為 ARM 架構而無法再繼續使用;經搜尋找到 Using SQL Server on M1 based Mac with Docker 並實作成功、紀錄如下:

一、Docker 已支援 ARM 、故可以直接由官網下載安裝(我使用 brew 的方式)。

brew install --cask docker

二、在 hub.codkcer.com 中找到 Azure SQL Edge 的 docker image 、並將其 pull 下來。

docker pull mcr.microsoft.com/azure-sql-edge

http://idea0816.synology.me/wordpress/wp-content/uploads/2023/05/截圖-2023-05-03-上午9.09.43.png

三、運行(特別注意密碼需為強密碼才不會有問題)。
20250220:修正以下運行指令

docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=Admin@123' -e 'MSSQL_PID=Developer' -e 'MSSQL_USER=SA' -p 1433:1433 --name azuresqledge -d mcr.microsoft.com/azure-sql-edge

http://idea0816.synology.me/wordpress/wp-content/uploads/2023/05/截圖-2023-05-03-上午9.16.52.png

四、如 HOW TO RESTORE SQL SERVER ON MAC USING DOCKER 提到的在 Azure Data Studio 連線資料庫。

http://idea0816.synology.me/wordpress/wp-content/uploads/2023/05/截圖-2023-05-03-上午9.20.53.png

Error Message:在新版的 Azure Data Studio 要 Restore 資料庫時可能會跳出「You must enable preview features in order to use restore」 的錯誤訊息。

http://idea0816.synology.me/wordpress/wp-content/uploads/2023/05/截圖-2023-05-03-上午10.26.02.png

要去 Setting 中將其打開、這樣在 Restore 時就不會出現錯誤了。

http://idea0816.synology.me/wordpress/wp-content/uploads/2023/05/截圖-2023-05-03-上午10.26.31.png

http://idea0816.synology.me/wordpress/wp-content/uploads/2023/05/截圖-2023-05-03-上午10.27.14.png

五、將備份資料庫拷貝進 Docker。

sudo docker cp database.bak Azuresqledge:/var/opt/mssql/backup

六、依之前方式 Restore Database 即可完成。