Подключение MSSQL db с помощью docker

#sql-server #docker #docker-compose #dockerfile

#sql-сервер #docker #docker-compose #dockerfile

Вопрос:

Я пытаюсь подключить MSSQL Db к docker.

Я пытался использовать документацию docker MSSQL, https://hub.docker.com/_/microsoft-mssql-server

Он запускает контейнер и немедленно останавливается, и я использовал следующие команды,

 docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=My_password' -p 1433:1433 --name db -d mcr.microsoft.com/mssql/server 
docker exec -it containername /opt/mssql-tools/bin/sqlcmd -S my_server_ip -U My_user -P My_password
  

Журналы контейнеров

 SQL Server 2019 will run as non-root by default.
This container is running as user mssql.
To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
2020-10-02 05:21:03.67 Server      Setup step is copying system data file 'C:templatedatamaster.mdf' to '/var/opt/mssql/data/master.mdf'.
2020-10-02 05:21:03.92 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-10-02 05:21:03.95 Server      Setup step is copying system data file 'C:templatedatamastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'.
2020-10-02 05:21:04.00 Server      Setup step is copying system data file 'C:templatedatamodel.mdf' to '/var/opt/mssql/data/model.mdf'.
2020-10-02 05:21:04.06 Server      Setup step is copying system data file 'C:templatedatamodellog.ldf' to '/var/opt/mssql/data/modellog.ldf'.
2020-10-02 05:21:04.12 Server      Setup step is copying system data file 'C:templatedatamsdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'.
2020-10-02 05:21:04.19 Server      Setup step is copying system data file 'C:templatedatamsdblog.ldf' to '/var/opt/mssql/data/msdblog.ldf'.
2020-10-02 05:21:04.27 Server      Setup step is FORCE copying system data file 'C:templatedatamodel_replicatedmaster.mdf' to '/var/opt/mssql/data/model_replicatedmaster.mdf'.
2020-10-02 05:21:04.35 Server      Setup step is FORCE copying system data file 'C:templatedatamodel_replicatedmaster.ldf' to '/var/opt/mssql/data/model_replicatedmaster.ldf'.
2020-10-02 05:21:04.42 Server      Setup step is FORCE copying system data file 'C:templatedatamodel_msdbdata.mdf' to '/var/opt/mssql/data/model_msdbdata.mdf'.
2020-10-02 05:21:04.53 Server      Setup step is FORCE copying system data file 'C:templatedatamodel_msdblog.ldf' to '/var/opt/mssql/data/model_msdblog.ldf'.
2020-10-02 05:21:05.01 Server      Microsoft SQL Server 2019 (RTM-CU7) (KB4570012) - 15.0.4063.15 (X64)
        Aug 15 2020 10:48:11
        Copyright (C) 2019 Microsoft Corporation
        Developer Edition (64-bit) on Linux (Ubuntu 18.04.5 LTS) <X64>
2020-10-02 05:21:05.03 Server      UTC adjustment: 0:00
2020-10-02 05:21:05.04 Server      (c) Microsoft Corporation.
2020-10-02 05:21:05.04 Server      All rights reserved.
2020-10-02 05:21:05.05 Server      Server process ID is 40.
2020-10-02 05:21:05.05 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2020-10-02 05:21:05.06 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-10-02 05:21:05.10 Server      SQL Server detected 1 sockets with 4 cores per socket and 8 logical processors per socket, 8 total logical processors; using 8 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2020-10-02 05:21:05.13 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2020-10-02 05:21:05.14 Server      Detected 5032 MB of RAM. This is an informational message; no user action is required.
2020-10-02 05:21:05.90 Server      Using conventional memory in the memory manager.
2020-10-02 05:21:05.92 Server      Page exclusion bitmap is enabled.
2020-10-02 05:21:05.97 Server      Buffer pool extension is not supported on Linux platform.
2020-10-02 05:21:05.97 Server      Buffer Pool: Allocating 1048576 bytes for 723370 hashPages.
2020-10-02 05:21:06.91 Server      Buffer pool extension is already disabled. No action is necessary.
2020-10-02 05:21:09.77 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-10-02 05:21:09.88 Server      Query Store settings initialized with enabled = 1,
2020-10-02 05:21:09.92 Server      The maximum number of dedicated administrator connections for this instance is '1'
2020-10-02 05:21:09.93 Server      Node configuration: node 0: CPU mask: 0x00000000000000ff:0 Active CPU mask: 0x00000000000000ff: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-10-02 05:21:09.97 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-10-02 05:21:10.02 Server      In-Memory OLTP initialized on lowend machine.
2020-10-02 05:21:10.10 Server      CLR version v4.0.30319 loaded.
2020-10-02 05:21:10.11 Server      [INFO] Created Extended Events session 'hkenginexesession'
2020-10-02 05:21:10.12 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-10-02 05:21:10.17 Server      Total Log Writer threads: 2. This is an informational message; no user action is required.
2020-10-02 05:21:10.18 Server      clflushopt is selected for pmem flush operation.
2020-10-02 05:21:10.20 Server      Software Usage Metrics is disabled.
2020-10-02 05:21:10.21 spid9s      [1]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-10-02 05:21:10.21 spid9s      Starting up database 'master'.
ForceFlush feature is enabled for log durability.
2020-10-02 05:21:10.79 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-10-02 05:21:10.98 Server      Common language runtime (CLR) functionality initialized.
2020-10-02 05:21:11.30 spid9s      Converting database 'master' from version 897 to the current version 904.
2020-10-02 05:21:11.31 spid9s      Database 'master' running the upgrade step from version 897 to version 898.
2020-10-02 05:21:11.56 spid9s      Database 'master' running the upgrade step from version 898 to version 899.
2020-10-02 05:21:11.85 spid9s      Database 'master' running the upgrade step from version 899 to version 900.
2020-10-02 05:21:12.14 spid9s      Database 'master' running the upgrade step from version 900 to version 901.
2020-10-02 05:21:12.38 spid9s      Database 'master' running the upgrade step from version 901 to version 902.
2020-10-02 05:21:12.90 spid9s      Database 'master' running the upgrade step from version 902 to version 903.
2020-10-02 05:21:13.13 spid9s      Database 'master' running the upgrade step from version 903 to version 904.
2020-10-02 05:21:14.13 spid9s      Resource governor reconfiguration succeeded.
2020-10-02 05:21:14.13 spid9s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2020-10-02 05:21:14.16 spid9s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2020-10-02 05:21:14.53 spid9s      SQL Trace ID 1 was started by login "sa".
2020-10-02 05:21:15.24 spid9s      Server name is '313c0fa336a7'. This is an informational message only. No user action is required.
2020-10-02 05:21:15.29 spid9s      [4]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-10-02 05:21:15.29 spid41s     Always On: The availability replica manager is starting. This is an informational message only. No user action is required.
2020-10-02 05:21:15.30 spid9s      Starting up database 'msdb'.
2020-10-02 05:21:15.31 spid41s     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-10-02 05:21:15.51 spid11s     [32767]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-10-02 05:21:15.52 spid11s     Starting up database 'mssqlsystemresource'.
2020-10-02 05:21:15.54 spid11s     The resource database build version is 15.00.4063. This is an informational message only. No user action is required.
2020-10-02 05:21:15.60 spid11s     [3]. Feature Status: PVS: 0. CTR: 0. ConcurrentPFSUpdate: 1.
2020-10-02 05:21:15.61 spid11s     Starting up database 'model'.
2020-10-02 05:21:15.76 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-10-02 05:21:16.29 spid11s     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-10-02 05:21:16.32 spid39s     Password policy update was successful.
2020-10-02 05:21:16.75 spid9s      Converting database 'msdb' from version 897 to the current version 904.
2020-10-02 05:21:16.76 spid9s      Database 'msdb' running the upgrade step from version 897 to version 898.
2020-10-02 05:21:16.77 spid39s     A self-generated certificate was successfully loaded for encryption.
2020-10-02 05:21:16.79 spid39s     Server is listening on [ 'any' <ipv6> 1433].
2020-10-02 05:21:16.80 spid39s     Server is listening on [ 'any' <ipv4> 1433].
2020-10-02 05:21:16.82 Server      Server is listening on [ ::1 <ipv6> 1434].
2020-10-02 05:21:16.82 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
2020-10-02 05:21:16.83 Server      Dedicated admin connection support was established for listening locally on port 1434.
2020-10-02 05:21:16.85 spid39s     Server is listening on [ ::1 <ipv6> 1431].
2020-10-02 05:21:16.86 spid39s     Server is listening on [ 127.0.0.1 <ipv4> 1431].
2020-10-02 05:21:16.87 spid39s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2020-10-02 05:21:17.24 spid11s     Converting database 'model' from version 897 to the current version 904.
2020-10-02 05:21:17.25 spid11s     Database 'model' running the upgrade step from version 897 to version 898.
2020-10-02 05:21:18.45 spid9s      Database 'msdb' running the upgrade step from version 898 to version 899.
2020-10-02 05:21:18.45 spid18s     ERROR: Unable to set system administrator password: Password validation failed. The password does not meet SQL Server password policy requirements because it is not complex enough. The password must be at least 8 characters long and contain characters from three of the following four sets: Uppercase letters, Lowercase letters, Base 10 digits, and Symbols..
2020-10-02 05:21:18.52 spid18s     An error occurred during server setup. See previous errors for more information.
2020-10-02 05:21:18.53 spid18s     SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.
2020-10-02 05:21:18.57 spid11s     Database 'model' running the upgrade step from version 898 to version 899
  

Я не знаю, как запустить мой sql-сервер с помощью файла docker-compose, я попробовал со следующим

 version: "3"
services:
  nsetest:
    image: my_image/abc
  dbconnect:
    image: mcr.microsoft.com/mssql/server
    environment:
        - ConnectionString=data source=100.10.143.192;Initial Catalog=sharedb;Integrated Security=True;User Id=vart;Password=adm;MultipleActiveResultSets=True;Pooling=False
        - ACCEPT_EULA=Y
  

Обычно, когда я запускаю свой код, он выдает мне некоторый вывод и сохраняется в моей базе данных.

Но когда я запускаю docker, мой код выполняется, и я получаю данные, но они не сохраняются в моей базе данных.

Он работает только в Master db, но мне нужно использовать другую базу данных.

пожалуйста, помогите в этом

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

1. Я использовал ту же команду, предоставленную вами, для запуска контейнера mssql. Попробуйте выполнить эту команду для доступа к mssql cmd : docker exec -it db /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P My_password . Я могу получить доступ к оболочке без остановки контейнера. Пожалуйста, поделитесь полными журналами контейнера на случай, если контейнер остановится через некоторое время.

2. Я добавил журналы контейнеров.. пожалуйста, изучите это, позвольте мне дать несколько предложений

Ответ №1:

В последней четвертой строке журналов контейнера четко описана проблема:

2020-10-02 05:21:18.45 ОШИБКА spid18s: не удалось установить пароль системного администратора: ошибка проверки пароля. Пароль не соответствует требованиям политики паролей SQL Server, поскольку он недостаточно сложный. Пароль должен быть длиной не менее 8 символов и содержать символы из трех из следующих четырех наборов: прописные буквы, строчные буквы, базовые 10 цифр и символы.

Ваш текущий пароль, My_password, не соответствует требованиям. Попробуйте установить надежный пароль, который включает прописные буквы, строчные буквы, базовые 10 цифр и символы.

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

1. Это работает как шарм!! Спасибо .. но как добавить эти вещи в мой файл docker-compose, потому что я вставляю данные в свою БД, я не знаю, как получить значения в моей БД при запуске моего образа