docker安装sqlserver

Posted Demonson

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker安装sqlserver相关的知识,希望对你有一定的参考价值。

1.查看镜像源

docker search mssql

NAME                                                  DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
microsoft/mssql-server-linux                          Deprecated SQL Server on Linux Container Rep…   1240                                    
microsoft/mssql-server-windows-developer              Official Microsoft SQL Server Developer Edit…   467                                     
microsoft/mssql-server-windows-express                Official Microsoft SQL Server Express Editio…   383                                     
microsoft/mssql-tools                                 Official images for Microsoft SQL Server Com…   51                                      
rsmoorthy/mssql                                       MSSQL Database (version SQL2000)                13                                      [OK]
datagrip/mssql-server-linux                           SQL Server and SQL Server tools on Linux(201…   11                                      [OK]
bitwarden/mssql                                       The Bitwarden database.                         9                                       
mcmoe/mssqldocker                                     Builds on microsoft/mssql-server-linux and a…   5                                       [OK]
gantrior/mssql-server-2014-express-windows-with-iis   mssql 2014 + IIS                                5                                       
liaisonintl/mssql-server-linux                        mssql-server-linux                              4                                       [OK]
microsoft/mssql-monitoring-influxdb                   Sample Image for Influxdb, This image is des…   3                                       
tsgkadot/mssql-tools                                  SQL Server tools on Linux (sqlcmd)              3                                       [OK]
ansibleplaybookbundle/mssql-apb                       MS SQL Server on Linux (APB)                    2                                       [OK]
ansibleplaybookbundle/mssql-remote-apb                An APB that deploys Microsoft SQL Server        1                                       [OK]
christianacca/mssql-server-windows-express            Fork of official microsoft/mssql-server-wind…   1                                       
microsoft/mssql-monitoring-collectd                   This Sample image is designed to work with t…   1                                       
sammiechan/mssqlubuntuwithfulltextsearch              MSSQL Ubuntu Docker Image with Full-Text Sea…   0                                       
octopusdeploy/mssql-server-windows-express            Fork of official microsoft/mssql-server-wind…   0                                       
tchughesiv/mssql-server-linux                         CentOS build                                    0                                       [OK]
iconviet/mssql                                                                                        0                                       
softwareplant/mssql                                   SQL Server test database                        0                                       [OK]
uwthalesians/mssql                                    Mssql Database Server for Perceptia             0                                       
danieloliver/mssql_exporter                           MSSQL Exporter for Prometheus                   0                                       
hdemirkale/mssql                                                                                      0                                       
agiper/mssql

2.拉取镜像

docker pull microsoft/mssql-server-linux

Using default tag: latest
latest: Pulling from microsoft/mssql-server-linux
59ab41dd721a: Pull complete 
57da90bec92c: Pull complete 
06fe57530625: Pull complete 
5a6315cba1ff: Pull complete 
739f58768b3f: Pull complete 
0b751601bca3: Pull complete 
bcf04a22644a: Pull complete 
6b5009e4f470: Pull complete 
a9dca2f6722a: Pull complete 
Digest: sha256:9b700672670bb3db4b212e8aef841ca79eb2fce7d5975a5ce35b7129a9b90ec0
Status: Downloaded newer image for microsoft/mssql-server-linux:latest
docker.io/microsoft/mssql-server-linux:latest

docker images

REPOSITORY                     TAG                 IMAGE ID            CREATED             SIZE
feisky/app                     mem-leak-fix        88b9a8aaeffa        11 months ago       73.9MB
feisky/app                     mem-leak            8949a3c07284        11 months ago       73.9MB
feisky/app                     io-cached           6a465f6f0be7        11 months ago       73.9MB
feisky/app                     io-direct           da0f397bc71e        11 months ago       73.9MB
ubuntu                         latest              adafef2e596e        11 months ago       73.9MB
mysql                          5.7.30              9cfcce23593a        12 months ago       448MB
microsoft/mssql-server-linux   latest              314918ddaedf        2 years ago         1.35GB

3.运行sqlserver容器

#开通端口
firewall-cmd --zone=public --add-port=11433/tcp --permanent
firewall-cmd --reload

#创建容器
docker run -d \\
-v /docker/mssql:/var/opt/mssql \\
-e 'ACCEPT_EULA=Y' \\
-e 'SA_PASSWORD=E6gps@1234' \\
-e 'MSSQL_PID=Enterprise' \\
-e 'MSSQL_LCID=2052' \\
-e TZ='Asia/Shanghai' \\
-p 11433:1433 \\
--name sqlserver \\
-d microsoft/mssql-server-linux

4.参数说明:

-e 'ACCEPT_EULA=Y'	         设置此参数说明同意 SQL SERVER 使用条款 , 否则无法使用
-e 'SA_PASSWORD=密码'	         此处设置 SQL SERVER 数据库 SA 账号的密码
-p 11433:1433	                 将宿主机 11433端口映射到容器的 1433 端口
--name sqlserver	         设置容器名为 mssql
-v /docker/mssql:/var/opt/mssql  将linux宿主机目录/docker/mssql 映射到容器 /var/opt/mssql , 方便备份数据
-d	                         在后台运行

5.连接数据库

#先进入容器
docker exec -it sqlserver bash

#使用命令在内部连接,在容器内部使用 sqlcmd 进行本地连接。 默认情况下,sqlcmd 不在路径之中,因此需要指定完整路径。
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P E6gps@1234

#创建数据库
CREATE DATABASE MyDB;
SELECT Name from sys.Databases;
GO

#退出
quit

6.启动代理

#进入docker
docker exec -it sqlserver bash

#启动SQL server代理
/opt/mssql/bin/mssql-conf set sqlagent.enabled true

SQL Server needs to be restarted in order to apply this setting. Please run
'systemctl restart mssql-server.service'.

#退出并重启容器
docker stop sqlserver
docker start sqlserver

#重新连接客户端

7.外部连接

 

版本

创建数据库

本地数据库目录

 

8.docker命令

docker images
docker ps -a
docker ps
docker stop XXX
docker rm XXX
docker rmi XXX

以上是关于docker安装sqlserver的主要内容,如果未能解决你的问题,请参考以下文章

sqlserver docker 安装部署试用

docker安装sqlserver

sqlserver 2017 docker安装(启动代理)

Docker安装SQL Server

使用Telegraf + Influxdb + Grafana 监控SQLserver服务器的运行状况

Docker删除报错:Error response from daemon: conflict: unable to delete 08b152afcfae (must be forced)(代码片段