docker安装sqlserver

2023-02-17 00:00:00 数据库 专区 订阅 容器 宿主

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…


octopusdeploy/mssql-server-windows-express Fork of official microsoft/mssql-server-wind…


tchughesiv/mssql-server-linux CentOS build [OK]


iconviet/mssql


softwareplant/mssql SQL Server test database [OK]


uwthalesians/mssql Mssql Database Server for Perceptia


danieloliver/mssql_exporter MSSQL Exporter for Prometheus


hdemirkale/mssql


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


    b751601bca3: 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


                本文来源https://www.modb.pro/db/77089

                相关文章