DEV Community

loading...
Cover image for      SQL Server on Linux via Docker

SQL Server on Linux via Docker

Mark Roxberry
Security driven developer and passionate software engineer, architect and consultant
Originally published at roxberry.dev ・1 min read
  1. Get Docker (if it is not already running)

  2. Get the SQL Server on Linux for Docker Engine image

I'm running Docker on MacOS, I will use the SQL Server on Linux for Docker Engine at Docker Hub

   docker pull microsoft/mssql-server-linux
Enter fullscreen mode Exit fullscreen mode
  1. Set the settings and start the container

SQL Server on Linux for Docker Engine requires an environment setting to accept the EULA and set a strong SA password:

   ACCEPT_EULA = Y
   SA_PASSWORD = <your password>
Enter fullscreen mode Exit fullscreen mode

Run this in the terminal:

   docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux
Enter fullscreen mode Exit fullscreen mode
  1. Copy a backup to the container
   docker cp '/tmp/DatabaseName.bak' mssql-server-linux:/tmp
Enter fullscreen mode Exit fullscreen mode
  1. Restore the backup
   RESTORE DATABASE DatabaseName FROM DISK='/tmp/DatabaseName.bak'
   WITH MOVE 'DatabaseName' TO '/var/opt/mssql/data/DatabaseName.MDF',
   MOVE 'DatabaseName_log' TO '/var/opt/mssql/data/DatabaseName_log.ldf'
   Go
Enter fullscreen mode Exit fullscreen mode
  1. Connect with a docker command or an IDE like DataGrip

JetBrains DataGrip IDE

Using SQL Server for Linux in Docker has allowed me to continue to develop using a Linux distro or macOS without needing to set up a VM to run the database backend.

Discussion (0)