Восстановить базу данных SQL Server с помощью образа Docker, выдающего ошибку входа в SA

#sql-server #docker #dockerfile #containers #sql-server-2017

#sql-сервер #docker #dockerfile #контейнеры #sql-server-2017

Вопрос:

Я пытаюсь восстановить базу данных SQL Server с помощью Docker. Я использую этот файл dockerFile и запустил команду сборки, я уже установил 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 amp; sleep 10 
    amp;amp; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Pwd12345' -i /tmp/restore-backup.sql 
    amp;amp; 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]
Драйвер Microsoft ODBC 17 для SQL Server: не удалось войти в систему для пользователя ‘SA’..
Драйвер Microsoft ODBC 17 для SQL Server: Поставщик TCP: код ошибки 0x2749.

Ниже приведен полный снимок выполнения.

 PS C:UsersDhruvDownloadsDocker 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 amp; sleep 10        amp;amp; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Pwd12345' -i /tmp/restore-backup.sql      amp;amp; 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:templatedatamaster.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:templatedatamastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'.
2020-09-05 11:53:29.66 Server      Setup step is copying system data file 'C:templatedatamodel.mdf' to '/var/opt/mssql/data/model.mdf'.
2020-09-05 11:53:29.71 Server      Setup step is copying system data file 'C:templatedatamodellog.ldf' to '/var/opt/mssql/data/modellog.ldf'.
2020-09-05 11:53:29.75 Server      Setup step is copying system data file 'C:templatedatamsdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'.
2020-09-05 11:53:29.80 Server      Setup step is copying system data file 'C:templatedatamsdblog.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:templatedatamodel_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:templatedatamodel_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:templatedatamodel_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:templatedatamodel_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 amp; sleep 10        amp;amp; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'Pwd12345' -i /tmp/restore-backup.sql      amp;amp; 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
  

Комментарии:

1. У вас случайно нет $ в вашем реальном пароле для sa , не так ли?

2. Я не использовал $ в своем пароле, пожалуйста, поправьте меня, если я не понял ваш вопрос.

3. Часто запуск службы sql занимает некоторое время, попробуйте добавить режим ожидания: RUN sleep 60

4. Помимо проблем с экранированием оболочки * nixy с символами доллара ($) и кавычек (» ‘), поскольку в Docker все еще необходимо соблюдать обычные старые правила надежного пароля SQL Server, например: Если используется в строке подключения OLE DB или ODBC, логин или пароль не должны содержать следующие символы: [] () , ; ? * ! @ =. ССЫЛКА: Надежные пароли

Ответ №1:

Я сменил пароль, как предложено AlwaysLearning, и изменил время ожидания на 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 amp; sleep 60 
    amp;amp; /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -i /tmp/restore-backup.sql 
    amp;amp; 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