Skip to content

Instantly share code, notes, and snippets.

@jakenuts
Last active June 5, 2023 18:22
Show Gist options
  • Save jakenuts/6ac082aca378fa4c268ccebb97391036 to your computer and use it in GitHub Desktop.
Save jakenuts/6ac082aca378fa4c268ccebb97391036 to your computer and use it in GitHub Desktop.
Containers

Running SQL Server in Container

Prereqs:

  • Docker Desktop
  • Windows Terminal (for cmdline on Windows and WSL)
  • WSL2

Start docker container with SQL 2022 in WSL2

sudo docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=aB#123s93j8!" \
   -p 1433:1433 --name sql1 --hostname sql1 \
   -d \
   mcr.microsoft.com/mssql/server:2022-latest

Check status of new container

sudo docker ps -a

Connect in container

Open terminal in container

sudo docker exec -it sql1 "bash"

Connect with sqlcmd

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "aB#123s93j8!"

CREATE DATABASE TestDB;

SELECT Name from sys.databases;

GO

Connect with Azure Data Studio

Server:   127.0.0.1
Auth:     SQL Login
Username: SA
Password: aB#123s93j8!

> I disabled encryption, trusted server cert

Next Steps

  • Learn about start/stop/resume container with data preserved
  • Using AutoExpress, Messaging databases in container

References

Quickstart: Run SQL Server Linux container images with Docker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment