Try   HackMD

Mac M1 download MSSQL via Docker

tags: tutor

參考教學影片:
https://www.youtube.com/watch?v=mLpBD8Kbc0k
參考文章:
https://www.twilio.com/blog/using-sql-server-on-macos-with-docker

前提-你已經裝好Docker Desktop

https://docs.docker.com/desktop/mac/apple-silicon/

Increase Docker's default memory allocation as SQL Server

打開Docker Desktop後在Preferences>Resources底下將Memory調高到至少4G

然後在你的cmd下這個指令

softwareupdate --install-rosetta

Download Azure Data Studio

下載網址:
https://learn.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver16
選擇macOS

下載azure-sql-edge image

docker run -d --name sql_server -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=請輸入高強度密碼" -e "MSSQL_PID=Developer" -e "MSSQL_USER=SA" -p 1433:1433 mcr.microsoft.com/azure-sql-edge

高強度密碼需要有大小寫英文及數字

以下是參數介紹:

  1. -d : will launch the container in "detached" mode and is optional. This means that containers will run in the background and you can close the terminal window.
  2. name : sql_server will assign a name to the container and is optional, but recommended for easier management!
  3. -e : will allow you to set environment variables:
    * 'ACCEPT_EULA=Y' SQL Server requires the user to accept the "End User Licence Agreement" or EULA. The Y here indicates acceptance.
    * 'SA_PASSWORD=someThingComplicated1234' is a required parameter for SQL Server. This is the System Administrator password. See the note below on password strength.
  4. -p : 1433:1433 will map the local port 1433 to port 1433 on the container. Port 1433 is the default TCP port that SQL Server will listen on.

成功下載完後可以進到docker desktop的container看是否有一個sql container正在running
如果有就代表成功了,他的格子會呈現綠色的,沒有跑成功會是灰色

Connect to Azure Data Studio

  1. Server第一次可以自取,建議就取localhost
  2. User name就是你在cmd下的"MSSQL_USER=SA"(注意大小寫)
  3. 密碼就是你在cmd下的"MSSQL_SA_PASSWORD=請輸入高強度密碼"
  4. 可以點選記住密碼
  5. connect

連線成功後點擊新增query就可以開始寫了!

問題解決 ZSH: command not found: docker

下載好docker desktop 但是在cmd打docker會報錯

參考文章:https://ruslan.rocks/posts/zsh-command-not-found-docker
參考文章:https://stackoverflow.com/questions/64009138/docker-command-not-found-when-running-on-mac

  1. knowing the path
echo $PATH

可以知道目前的路徑有那些
2. going to shell cofiguration file
文章:https://zwbetz.com/shell-config-file-on-mac/
根據上述文章去看你目前的bash是哪一個
我的是zsh所以是找.zprofile
到finder command+shift+g 輸入.zprofile 透過文字編輯器打開
4. Adding Docker to the $PATH environment variable

export PATH=$PATH:/Applications/Docker.app/Contents/Resources/bin/

  1. restart zsh
exec zsh