Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.

SQL Server on Linux via Docker

posted on August 25, 2017 | tags: [ sql server, linux, docker ]
main post image
Running SQL Server on Linux for Docker Engine
  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
    
  3. 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>
    

    Run this in the terminal:

    docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourStrong(!)Password' -p 1433:1433 -d microsoft/mssql-server-linux
    
  4. Copy a backup to the container

    docker cp '/tmp/DatabaseName.bak' mssql-server-linux:/tmp
    
  5. 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
    
  6. Connect with a docker command or an IDE like DataGrip

DataGrip SQL Server Connection

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.