DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Tools
  4. Running SQL Server on a Linux Container Using Docker for Windows

Running SQL Server on a Linux Container Using Docker for Windows

If you have a need to do this, then this is the post for you as we walk you through the processes to help you get started using a DevOps workflow with these technologies.

Simon Foster user avatar by
Simon Foster
·
Nov. 07, 18 · Presentation
Like (1)
Save
Tweet
Share
12.89K Views

Join the DZone community and get the full member experience.

Join For Free

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 set up how you want.

However, since Microsoft has 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.

Docker (software) sql Linux (operating system)

Published at DZone with permission of Simon Foster, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Three SQL Keywords in QuestDB for Finding Missing Data
  • How to Cut the Release Inspection Time From 4 Days to 4 Hours
  • SAST: How Code Analysis Tools Look for Security Flaws
  • Public Cloud-to-Cloud Repatriation Trend

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: