Docker Sql

已裝net core及AP後,來試試DB的部份

這次選擇 SQL Server On Linux

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. 選擇 sql version 去pull下 :  docker pull microsoft/mssql-server-linux

2. 運行 sql 

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<密碼>" -p 1433:1433 --name SQL名稱 -d microsoft/mssql-server-linux (Sql Version) ,

" 很重要符號

密碼 :  Password validation failed. The password does not meet SQL Server password policy requirements because it is too short. The password must be at least 8 characters..

trouble : Error response from daemon: Conflict. The container name "/Container名稱" is already in use by container . You have to remove (or rename) that container to be able to reuse that name.

solution : docker rm Container名稱

3. 檢查目前運行的container 狀況 : docker ps

4. 查詢運行的IP : docker inspect --format "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" containerID

5.透過SSMS  tool,進行登入,就可以開始操作Sql

6. docker logs ContainerID 查詢狀況

7. 外部匯入.bak檔,restore db (.bak .mdf)

https://docs.microsoft.com/zh-tw/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-ver15

SQL Server 容器內建立目錄 : docker exec -it SQL名稱 mkdir /var/opt/mssql/backup

docker cp 容器與主機間數據copy : docker cp 實際Path ContainerID : path

8. push dockhub

登入hub : docker login

複制image 一份 : docker tag RepositoryName dockhubID/上傳Name

上傳 : docker push dockhubID/上傳Name

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ref : https://docs.microsoft.com/zh-tw/sql/linux/quickstart-install-connect-docker?view=sql-server-ver15&pivots=cs1-bash

https://mileslin.github.io/2019/04/SQL-Server-Container-%E5%BF%AB%E9%80%9F%E5%85%A5%E9%96%80/

https://bryanyu.github.io/2018/04/11/DockerFirst/

https://edwardkuo.imas.tw/paper/2017/04/08/Docker/DockerSQL/

https://www.runoob.com/docker/docker-cp-command.html

https://ithelp.ithome.com.tw/articles/10191139