May 26, 2022: DataStation 0.11.0 is released! Read more

Running SQL Server in a container on Github Actions

Published on by

In building out integration tests for DataStation recently I set up SQL Server. I didn't think this would be possible because Microsoft (and Oracle and IBM) normally require you to manually sign in to download their databases. However, Microsoft provides Docker images and allows you to accept their UELA in the command line.

So in my Github Actions run steps I added a call to Docker run:

    # Start up sqlserver
    - run: docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=1StrongPwd!!" -p 1433:1433 -d

Now the Docker image docs say to set a SA_PASSWORD environment variable instead of MSSQL_SA_PASSWORD but I tried that and couldn't connect when setting that or both SA_PASSWORD and MSSQ_SA_PASSWORD.

Once this Docker image is running you'll be able to connect to the master database with the sa user and the above password. It's important that if you use a different password it fulfills all the complexity requirements listed on the Docker image documentation.

Now in Go code you can connect using go-mssqldb with the connection string sa:1StrongPwd!!@tcp(localhost:1433)/master.

The only difficult part of this recipe once is that it's hard to debug when you've set up the password incorrectly (not fulfilling complexity requirements) or if you mistype an environment variable. Maybe if I checked the Docker logs for the SQL Server container it would have given me useful information. Instead I stumbled toward a working setup through guess and check.


With questions, criticism or ideas, email or Tweet me.

Also, check out DataStation and dsq.