Installing and Using Microsoft SQL Server on Linux (Docker)

30 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Starting with SQL Server 2017, MSSQL professionals can take advantage of the benefits of containerization. Whether we’re looking to consolidate several workloads onto a single server or just want a means of delivering consistent environments to our developers, deploying SQL Server via containers may be the solution we’re looking for.

In this hands-on lab we utilize Docker to work with the latest SQL Server 2017 image. Basic knowledge of Docker and Microsoft SQL Server are recommended.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Pull the SQL Server 2017 Linux Container Image
  1. Pull the latest SQL Server 2017 image from Microsoft Container Registry:

    sudo docker pull mcr.microsoft.com/mssql/server:2017-latest
Run the SQL Server 2017 Image
  1. Run the container using the following command. Set the SA password to anything, being careful to follow the SQL Server default password policy. By default, this creates a container running Developer edition.

    sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=AwesomePassword!' 
    -p 1433:1433 --name sql1 
    -d mcr.microsoft.com/mssql/server:2017-latest
  1. Verify the container is running.

    sudo docker ps -a
Connect To and Administer the Container
  1. Start an interactive bash shell inside the SQL Server container, using the name specified at creation.

    sudo docker exec -it sql1 "bash"
  1. Once inside, connect locally using SQLCMD. We must use the full path as SQLCMD is not in the path by default.

    /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'AwesomePassword!'
  2. Create a new database for our flagship application.

    CREATE DATABASE AwesomeCompany;
    go
  3. Verify this database now exists.

    SELECT Name from sys.Databases;
    go
  4. Create a login the application can use to connect.

    CREATE LOGIN AwesomeLogin WITH PASSWORD = 'AwesomePassword!';
    go
  5. Create a user for the new database and associate it with the login.

    USE AwesomeCompany;
    go
    CREATE USER AwesomeUser FOR LOGIN AwesomeLogin;
    go
  6. Give the new user permission to manage the database.

    exec sp_addrolemember 'db_owner', 'AwesomeUser';
    go
Verify Your Application Can Connect and Manage the Image
  1. Exit out of SQLCMD.
    quit

  2. Connect using the new login.

    /opt/mssql-tools/bin/sqlcmd -S localhost -U AwesomeLogin -P 'AwesomePassword!'
  3. Create a table and insert values into the new database.
    USE AwesomeCompany;
    go
    CREATE TABLE Inventory (id INT, name NVARCHAR(50), quantity INT)
    INSERT INTO Inventory VALUES (1, ‘widget’, 100);
    go

  4. Select data from the new table.

    SELECT * FROM Inventory;
    go

Additional Resources

Your company's flagship application uses Microsoft SQL Server for its backend database. In order to take advantage of the many benefits of containerization, you are investigating migration to a SQL Server 2017 Docker container. As a first step you are deploying the Docker image and verifying that your flagship application can connect to and manage it.

In summary we need to do the following:

  • Pull the SQL Server 2017 Linux container image.
  • Run the SQL Server 2017 image.
  • Connect to and administer the container.
  • Verify our application can connect and manage the image.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!