首页 新闻 会员 周边

持续集成中使用 SQL Server Linux 版 Docker 镜像的问题

0
悬赏园豆:30 [已解决问题] 解决于 2020-02-29 14:31

使用的 SQL Server 容器镜像是 mcr.microsoft.com/mssql/server:2017-latest-ubuntu,跑 CI 时出现下的错误,请问如何解决?

Microsoft.Data.SqlClient.SqlException : An unexpected error occurred while checking the sector size for file '/var/opt/mssql/data/BlogTestDb6_log.ldf'. Move the file to a local NTFS volume, where the sector size can be retrieved. Check the SQL Server error log for more information.

CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
问题补充:

持续集成是用 gitlab-ci runner 跑的

dudu的主页 dudu | 高人七级 | 园豆:30994
提问于:2020-02-29 11:33
< >
分享
最佳答案
0

排查过程:

1)进入 mssql 容器检查 /var/opt/mssql/data/ 路径是否存在。

# docker run -it mcr.microsoft.com/mssql/server:2017-latest-ubuntu ls /var/opt/mssql/data
SQL Server 2019 will run as non-root by default.
This container is running as user root.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
ls: cannot access '/var/opt/mssql/data': No such file or directory

默认竟然不存在这个路径。

2)进一步查看发现连 /var/opt/mssql 这个路径也不存在,根据微软的帮助文档,默认 data 路径就是 /var/opt/mssql/data

The filelocation.defaultdatadir and filelocation.defaultlogdir settings change the location where the new database and log files are created. By default, this location is /var/opt/mssql/data

3)为什么不在容器内为默认路径创建文件夹?微软意图何在?是失误还是“别有用心”?。。。想明白了,应该是微软的用心良苦,不给人犯错的机会——将数据文件放在容器内,必需通过 mount volume 映射到本机路径到 /var/opt/mssql/data

4)对于这里的持续集成场景,测试数据用完就作废,保存在容器内完全没问题,既然默认没有 /var/opt/mssql/data 目录,那就在容器启动时创建这个目录吧。

5)解决方法:在 .gitlab-ci.yml 中修改 mssql 容器启动命令,在启动时创建 /var/opt/mssql/data 目录。

- name: mcr.microsoft.com/mssql/server:2017-latest-ubuntu
    alias: dbserver-test
    command: ["sh", "-c", "mkdir -p /var/opt/mssql/data && /opt/mssql/bin/sqlservr"]
dudu | 高人七级 |园豆:30994 | 2020-02-29 14:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册