未加星标

Running SQL Server on a Linux Container using Docker for Windows

字体大小 | |
[数据库(mssql) 所属分类 数据库(mssql) | 发布者 店小二04 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

Recently I have been investigating what all the fuss is about Docker and it has been well worth my time as Docker is pretty awesome for automating stuff.

My development environment has typically required installing SQL Server. SQL is a bit of a beast with lots of options and takes time to setup how you want.

However since Microsoft have now created a version of SQL Server that runs on linux you can run SQL Server in a Linux container with only a few commands.

I am going to assume you already have Docker for windows installed on your development machine. If not head over to Docker and find out how.

The Microsoft guide to setting up SQL Server in a Linux container can be found here.

First you need to download the image. In a powershell window run:

docker pull mcr.microsoft.com/mssql/server:2017-latest

This downloads the latest sql server image.

To run this image run the following:

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=password" -p 1433:1433 --name sql -d mcr.microsoft.com/mssql/server:2017-latest

To run a SQL Server image you are required to accept the terms and conditions and set a default sa password. These are added as environment variables with the -e flag.

You also need to set the ports that your container will run on (1433 is the default SQL port) and give your container a name, in this case “sql”.

If you have already installed SQL Server you will not be able to run the container on the same port as your local install. To solve this you can select a different port.

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=password" -p 1434:1433 --name sql -d mcr.microsoft.com/mssql/server:2017-latest

-p 1434:1433 maps the 1433 port on the container to port 1434 of your local environment.

Once you have run this command you can connect SQL Server Management Studio (SSMS) to (local) or (local),1434 if you are using a different port using the credentials you provided and execute any SQL you like.

If your development environment requires windows authentication this of course is not for you, if it doesn’t you are good to go.

The development environment I have been using has various powershell scripts for setting things up. These assume windows auth. However I have adapted them to take custom credentials.

$credential=Get-Credential $server.ConnectionContext.LoginSecure=$false $server.ConnectionContext.set_Login($credential.UserName) $server.ConnectionContext.set_SecurePassword($credential.Password)

The Get-Credential command creates a dialog where you can enter SQL credentials, this is then stored in a variable and used in the rest of the script.

How do I restore a backup file to my container?

Run:

docker exec -it sql mkdir /var/opt/mssql/backup docker cp database.bak sql:/var/opt/mssql/backup

This creates a backup folder and copies a backup file from your local environment to the container. You can then use management studio to restore the backup file (or you could write a sql script to do it). One thing to note when restoring databases, make sure the files are restored to Linux locations not windows locations.

The only issues I have encountered so far are the lack of support for SSIS packages and no windows auth. There are sql server windows images available which I haven’t tried yet which may work better with some of these options.

This post has already been read 6 times!

本文数据库(mssql)相关术语:熊片数据库 mssql数据库 oracle数据库 pubmed数据库 access数据库 万方数据库

代码区博客精选文章
分页:12
转载请注明
本文标题:Running SQL Server on a Linux Container using Docker for Windows
本站链接:https://www.codesec.net/view/610768.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(mssql) | 评论(0) | 阅读(132)