使用提供SA登录错误的Docker映像还原SQL Server数据库

如何解决使用提供SA登录错误的Docker映像还原SQL Server数据库

我正在尝试使用Docker还原SQL Server数据库。我正在使用此dockerFile并运行build命令,我已经在计算机上安装了SQL Server 2017。

FROM mcr.microsoft.com/mssql/server:2019-latest AS build
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Pwd12345
ENV MSSQL_PID=Enterprise

WORKDIR /tmp
COPY AdventureWorksLT2017.bak .
COPY restore-backup.sql .
  
RUN /opt/mssql/bin/sqlservr --accept-eula & sleep 10 \
    && /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Pwd12345' -i /tmp/restore-backup.sql \
    && pkill sqlservr

FROM mcr.microsoft.com/mssql/server:2019-latest AS release
ENV ACCEPT_EULA=Y
ENV SA_PASSWORD=Pwd12345

COPY --from=build /var/opt/mssql/data /var/opt/mssql/data

但是在还原我的SQL Server数据库时出现以下错误

错误:18456,严重性:14,状态:7。
用户“ SA”的登录失败。原因:评估密码时发生错误。 [客户:172.17.0.2]
SQL Server的Microsoft ODBC驱动程序17:用户'SA'登录失败。.
用于SQL Server的Microsoft ODBC驱动程序17:TCP提供程序:错误代码0x2749。

下面是执行的完整快照。

PS C:\Users\Dhruv\Downloads\Docker with SQL> docker build -t restored-db .
Sending build context to Docker daemon  7.548MB
Step 1/12 : FROM mcr.microsoft.com/mssql/server:2019-latest AS build
2019-latest: Pulling from mssql/server
5b7339215d1d: Pull complete
14ca88e9f672: Pull complete
a31c3b1caad4: Pull complete
b054a26005b7: Pull complete
59f979819d9b: Pull complete
29eb18117119: Pull complete
e0607dd0db6f: Pull complete
b87654acc43f: Pull complete
Digest: sha256:c7e1ece8ec34938c78d715eb5d2ddc827f0b92debc071dcfca122a6f94ce540d
Status: Downloaded newer image for mcr.microsoft.com/mssql/server:2019-latest
 ---> 8d8453707e16
Step 2/12 : ENV ACCEPT_EULA=Y
 ---> Running in 364206e05ac8
Removing intermediate container 364206e05ac8
 ---> 31c051fd4567
Step 3/12 : ENV SA_PASSWORD=Pwd12345
 ---> Running in be7548fee19f
Removing intermediate container be7548fee19f
 ---> 467c830d396d
Step 4/12 : ENV MSSQL_PID=Enterprise
 ---> Running in 490207525c24
Removing intermediate container 490207525c24
 ---> 251f16905093
Step 5/12 : WORKDIR /tmp
 ---> Running in a1e442d92e9a
Removing intermediate container a1e442d92e9a
 ---> 540549c2f5f7
Step 6/12 : COPY AdventureWorksLT2017.bak .
 ---> 0ba530da54c3
Step 7/12 : COPY restore-backup.sql .
 ---> 1acf41f50e96
Step 8/12 : RUN /opt/mssql/bin/sqlservr --accept-eula & sleep 10        && /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Pwd12345' -i /tmp/restore-backup.sql      && pkill sqlservr
 ---> Running in 24070118cc8b
2020-09-05 11:53:27.83 Server      The licensing PID was successfully processed. The new edition is [Enterprise Edition].
2020-09-05 11:53:29.52 Server      Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2020-09-05 11:53:29.56 Server      Did not find an existing master data file /var/opt/mssql/data/master.mdf,copying the missing default master and other system database files. If you have moved the database location,but not moved the database files,startup may fail. To repair: shutdown SQL Server,move the master database to configured location,and restart.
2020-09-05 11:53:29.62 Server      Setup step is copying system data file 'C:\templatedata\mastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'.
2020-09-05 11:53:29.66 Server      Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql/data/model.mdf'.
2020-09-05 11:53:29.71 Server      Setup step is copying system data file 'C:\templatedata\modellog.ldf' to '/var/opt/mssql/data/modellog.ldf'.
2020-09-05 11:53:29.75 Server      Setup step is copying system data file 'C:\templatedata\msdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'.
2020-09-05 11:53:29.80 Server      Setup step is copying system data file 'C:\templatedata\msdblog.ldf' to '/var/opt/mssql/data/msdblog.ldf'.
2020-09-05 11:53:29.84 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.mdf' to '/var/opt/mssql/data/model_replicatedmaster.mdf'.
2020-09-05 11:53:29.88 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.ldf' to '/var/opt/mssql/data/model_replicatedmaster.ldf'.
2020-09-05 11:53:29.91 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_msdbdata.mdf' to '/var/opt/mssql/data/model_msdbdata.mdf'.
2020-09-05 11:53:29.96 Server      Setup step is FORCE copying system data file 'C:\templatedata\model_msdblog.ldf' to '/var/opt/mssql/data/model_msdblog.ldf'.
2020-09-05 11:53:30.27 Server      Microsoft SQL Server 2019 (RTM-CU7) (KB4570012) - 15.0.4063.15 (X64)
        Aug 15 2020 10:48:11
        Copyright (C) 2019 Microsoft Corporation
        Enterprise Edition (64-bit) on Linux (Ubuntu 18.04.5 LTS) <X64>
2020-09-05 11:53:30.31 Server      UTC adjustment: 0:00
2020-09-05 11:53:30.32 Server      (c) Microsoft Corporation.
2020-09-05 11:53:30.33 Server      All rights reserved.
2020-09-05 11:53:30.34 Server      Server process ID is 40.
2020-09-05 11:53:30.35 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2020-09-05 11:53:30.36 Server      Registry startup parameters:
         -d /var/opt/mssql/data/master.mdf
         -l /var/opt/mssql/data/mastlog.ldf
         -e /var/opt/mssql/log/errorlog
2020-09-05 11:53:30.38 Server      Command Line Startup Parameters:
         --accept-eula
2020-09-05 11:53:30.40 Server      SQL Server detected 1 sockets with 2 cores per socket and 4 logical processors per socket,4 total logical processors; using 4 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2020-09-05 11:53:30.43 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2020-09-05 11:53:30.45 Server      Detected 5013 MB of RAM. This is an informational message; no user action is required.
2020-09-05 11:53:30.47 Server      Using conventional memory in the memory manager.
2020-09-05 11:53:30.49 Server      Page exclusion bitmap is enabled.
2020-09-05 11:53:30.54 Server      Buffer pool extension is not supported on Linux platform.
2020-09-05 11:53:30.56 Server      Buffer Pool: Allocating 1048576 bytes for 722742 hashPages.
2020-09-05 11:53:31.64 Server      Buffer pool extension is already disabled. No action is necessary.
2020-09-05 11:53:34.87 Server      Successfully initialized the TLS configuration. Allowed TLS protocol versions are ['1.0 1.1 1.2']. Allowed TLS ciphers are ['ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA'].
2020-09-05 11:53:35.01 Server      Query Store settings initialized with enabled = 1,2020-09-05 11:53:35.06 Server      The maximum number of dedicated administrator connections for this instance is '1'
2020-09-05 11:53:35.06 Server      Node configuration: node 0: CPU mask: 0x000000000000000f:0 Active CPU mask: 0x000000000000000f:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2020-09-05 11:53:35.13 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2020-09-05 11:53:35.21 Server      In-Memory OLTP initialized on lowend machine.
2020-09-05 11:53:35.31 Server      CLR version v4.0.30319 loaded.
2020-09-05 11:53:35.40 Server      [INFO] Created Extended Events session 'hkenginexesession'
2020-09-05 11:53:35.41 Server      Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
ForceFlush is enabled for this instance.
2020-09-05 11:53:35.46 Server      Total Log Writer threads: 2. This is an informational message; no user action is required.
2020-09-05 11:53:35.49 Server      clflushopt is selected for pmem flush operation.
2020-09-05 11:53:35.50 Server      Software Usage Metrics is disabled.
2020-09-05 11:53:35.52 spid9s      [1]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-09-05 11:53:35.54 spid9s      Starting up database 'master'.
ForceFlush feature is enabled for log durability.
2020-09-05 11:53:35.85 spid9s      The tail of the log for database master is being rewritten to match the new sector size of 4096 bytes.  3584 bytes at offset 393728 in file /var/opt/mssql/data/mastlog.ldf will be written.
2020-09-05 11:53:35.95 Server      Common language runtime (CLR) functionality initialized.
2020-09-05 11:53:36.27 spid9s      Converting database 'master' from version 897 to the current version 904.
2020-09-05 11:53:36.28 spid9s      Database 'master' running the upgrade step from version 897 to version 898.
2020-09-05 11:53:36.35 spid9s      Database 'master' running the upgrade step from version 898 to version 899.
2020-09-05 11:53:36.47 spid9s      Database 'master' running the upgrade step from version 899 to version 900.
2020-09-05 11:53:36.50 spid9s      Database 'master' running the upgrade step from version 900 to version 901.
2020-09-05 11:53:36.53 spid9s      Database 'master' running the upgrade step from version 901 to version 902.
2020-09-05 11:53:36.58 spid9s      Database 'master' running the upgrade step from version 902 to version 903.
2020-09-05 11:53:36.61 spid9s      Database 'master' running the upgrade step from version 903 to version 904.
2020-09-05 11:53:37.06 spid9s      Resource governor reconfiguration succeeded.
2020-09-05 11:53:37.08 spid9s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2020-09-05 11:53:37.10 spid9s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2020-09-05 11:53:37.21 spid9s      SQL Trace ID 1 was started by login "sa".
2020-09-05 11:53:37.27 spid9s      Server name is '66d529291286'. This is an informational message only. No user action is required.
2020-09-05 11:53:37.33 spid36s     Password policy update was successful.
2020-09-05 11:53:37.36 spid9s      [4]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-09-05 11:53:37.37 spid12s     [32767]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-09-05 11:53:37.38 spid9s      Starting up database 'msdb'.
2020-09-05 11:53:37.40 spid39s     Always On: The availability replica manager is starting. This is an informational message only. No user action is required.
2020-09-05 11:53:37.42 spid12s     Starting up database 'mssqlsystemresource'.
2020-09-05 11:53:37.44 spid39s     Always On: The availability replica manager is waiting for the instance of SQL Server to allow client connections. This is an informational message only. No user action is required.
2020-09-05 11:53:37.49 spid12s     The resource database build version is 15.00.4063. This is an informational message only. No user action is required.
2020-09-05 11:53:37.58 spid12s     [3]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-09-05 11:53:37.59 spid12s     Starting up database 'model'.
2020-09-05 11:53:37.81 spid9s      The tail of the log for database msdb is being rewritten to match the new sector size of 4096 bytes.  3072 bytes at offset 50176 in file /var/opt/mssql/data/MSDBLog.ldf will be written.
2020-09-05 11:53:37.87 spid36s     A self-generated certificate was successfully loaded for encryption.
2020-09-05 11:53:37.89 spid36s     Server is listening on [ 'any' <ipv6> 1433].
2020-09-05 11:53:37.91 spid36s     Server is listening on [ 'any' <ipv4> 1433].
2020-09-05 11:53:37.95 Server      Server is listening on [ ::1 <ipv6> 1434].
2020-09-05 11:53:37.96 spid12s     The tail of the log for database model is being rewritten to match the new sector size of 4096 bytes.  512 bytes at offset 73216 in file /var/opt/mssql/data/modellog.ldf will be written.
2020-09-05 11:53:37.98 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
2020-09-05 11:53:38.00 Server      Dedicated admin connection support was established for listening locally on port 1434.
2020-09-05 11:53:38.04 spid36s     Server is listening on [ ::1 <ipv6> 1431].
2020-09-05 11:53:38.06 spid36s     Server is listening on [ 127.0.0.1 <ipv4> 1431].
2020-09-05 11:53:38.08 spid36s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2020-09-05 11:53:38.08 spid9s      Converting database 'msdb' from version 897 to the current version 904.
2020-09-05 11:53:38.11 spid9s      Database 'msdb' running the upgrade step from version 897 to version 898.
2020-09-05 11:53:38.16 spid12s     Converting database 'model' from version 897 to the current version 904.
2020-09-05 11:53:38.18 spid12s     Database 'model' running the upgrade step from version 897 to version 898.
2020-09-05 11:53:38.20 spid9s      Database 'msdb' running the upgrade step from version 898 to version 899.
2020-09-05 11:53:38.24 spid12s     Database 'model' running the upgrade step from version 898 to version 899.
2020-09-05 11:53:38.28 spid9s      Database 'msdb' running the upgrade step from version 899 to version 900.
2020-09-05 11:53:38.30 spid12s     Database 'model' running the upgrade step from version 899 to version 900.
2020-09-05 11:53:38.43 spid9s      Database 'msdb' running the upgrade step from version 900 to version 901.
2020-09-05 11:53:38.43 spid12s     Database 'model' running the upgrade step from version 900 to version 901.
2020-09-05 11:53:38.44 Logon       Error: 18456,Severity: 14,State: 7.
**2020-09-05 11:53:38.44 Logon       Login failed for user 'SA'. Reason: An error occurred while evaluating the password. [CLIENT: 172.17.0.2]
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'..
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : TCP Provider: Error code 0x2749.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..**
The command '/bin/sh -c /opt/mssql/bin/sqlservr --accept-eula & sleep 10        && /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Pwd12345' -i /tmp/restore-backup.sql      && pkill sqlservr' returned a non-zero code: 1

请帮助了解为什么我在还原数据库时会遇到这种问题。

当我手动执行恢复过程时,它工作正常。我正在按照以下步骤还原我的数据库

Step 1:-


docker run `
   -e "ACCEPT_EULA=Y" `
   -e "MSSQL_SA_PASSWORD=YourStrong!Passw0rd" `
   --name "sqlTechno" `
   -p 1401:1433 `
   -v sql1data:/var/opt/mssql `
   -d mcr.microsoft.com/mssql/server:2019-latest


Step 2:-

docker exec -it sqlTechno mkdir /var/opt/mssql/backup

Step 3:-

docker cp AdventureWorksLT2017.bak sqlTechno:/var/opt/mssql/backup

解决方法

我已按照AlwaysLearning的建议更改了密码,并根据Preben Huybrechts的建议将睡眠时间更改为60秒,而不是10秒。

最终工作代码段如下。

FROM mcr.microsoft.com/mssql/server:2017-latest AS build
ENV ACCEPT_EULA=Y
ENV MSSQL_SA_PASSWORD=YourStrong!Passw0rd

WORKDIR /tmp
COPY AdventureWorksLT2017.bak .
COPY restore-backup.sql .
  
RUN /opt/mssql/bin/sqlservr --accept-eula & sleep 60 \
    && /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -i /tmp/restore-backup.sql \
    && pkill sqlservr

FROM mcr.microsoft.com/mssql/server:2017-latest AS release
ENV ACCEPT_EULA=Y

COPY --from=build /var/opt/mssql/data /var/opt/mssql/data

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-