Skip to main content

Docker 上的 SQL Server

要使用 Docker 运行 Microsoft SQL Server 容器映像:

¥To run a Microsoft SQL Server container image with Docker:

  1. 安装并设置 Docker

    ¥Install and set up Docker

  2. 在终端中运行以下命令来下载 Microsoft SQL Server 2019 映像:

    ¥Run the following command in your terminal to download the Microsoft SQL Server 2019 image:

    docker pull mcr.microsoft.com/mssql/server:2019-latest
  3. 创建容器映像的实例,将 SA_PASSWORD 的值替换为你选择的密码:

    ¥Create an instance of the container image, replacing the value of SA_PASSWORD with a password of your choice:

    docker run --name sql_container -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=myPassword' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
  4. 按照 Microsoft 的说明连接 SQL Server 并使用 sqlcmd 工具,将镜像名称和密码替换为你自己的。

    ¥Follow Microsoft's instructions to connect to SQL Server and use the sqlcmd tool, replacing the image name and password with your own.

  5. sqlcmd 命令提示符下,创建一个新数据库:

    ¥From the sqlcmd command prompt, create a new database:

    CREATE DATABASE quickstart
    GO
  6. 运行以下命令检查数据库是否已成功创建:

    ¥Run the following command to check that your database was created successfully:

    sp_databases
    GO

连接 URL 凭据

¥Connection URL credentials

根据此示例,你的凭据是:

¥Based on this example, your credentials are:

  • 用户名:sa

    ¥Username: sa

  • 密码:我的密码

    ¥Password: myPassword

  • 数据库:快速开始

    ¥Database: quickstart

  • 港口:1433

    ¥Port: 1433