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)

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 :