sql-server - 将 MSSQL 数据库与 docker 连接

标签 sql-server 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:\templatedata\master.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:\templatedata\mastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'.
2020-10-02 05:21:04.00 Server      Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql/data/model.mdf'.
2020-10-02 05:21:04.06 Server      Setup step is copying system data file 'C:\templatedata\modellog.ldf' to '/var/opt/mssql/data/modellog.ldf'.
2020-10-02 05:21:04.12 Server      Setup step is copying system data file 'C:\templatedata\msdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'.
2020-10-02 05:21:04.19 Server      Setup step is copying system data file 'C:\templatedata\msdblog.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:\templatedata\model_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:\templatedata\model_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:\templatedata\model_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:\templatedata\model_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
我不知道如何使用 docker-compose 文件运行我的 sql 服务器,我尝试了以下
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 运行时,我的代码正在运行并且我正在获取数据,但它没有存储在我的数据库中。
它仅在主数据库中运行,但我需要使用其他数据库。
请帮忙

最佳答案

容器日志的倒数第四行清楚地描述了这个问题:

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.


您当前的密码,我的密码 , 不符合要求。尝试设置一个包含大写字母、小写字母、Base 10 数字和符号的强密码。

关于sql-server - 将 MSSQL 数据库与 docker 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64155597/

相关文章:

sql - 在更新记录时锁定记录的最佳方法是什么?

sql-server - SQLSTATE[IMSSP] : Tried to bind parameter number 2101. SQL Server 支持最多 2100 个参数

SQL IF block 代码导致错误,即使它不应该执行

docker - 无法使用docker-compose运行Registrator。获取连接被拒绝错误

proxy - 为什么我的 kubernetes 服务找不到端点?

php - Alpine Linux 上的甲骨文

docker - Intellij docker 集成插件和 docker-machine for windows 10 上的无效卷规范

SQL 别名无法识别

ruby - Build上的Docker Ruby Bundle权限错误

mysql - 为什么运行 docker 容器后 mysql 数据所有权更改为 systemd-journal-remote