A Docker Compose configuration for running SQL Server for Linux with Full Text Search enabled. Also includes the AdventureWorks sample database.
Tip
You can install both prerequisites on macOS using Homebrew:
brew install --cask docker
brew install sqlcmd
This will build the image and start a container named mssql
in the background.
docker compose -p mssql up -d --build
The container will start and perform some initial configuration on the database server. Give it a few seconds to finish up.
Once it's done, you can connect to the database from your local machine using sqlcmd
.
sqlcmd -U dev -P Test1234 -C
Tip
Not sure if the database server is ready? You can check the container's logs to monitor
its progress either in Docker Desktop or by running docker logs mssql -f
. You'll know
it's ready when you see the message *** SQL Server is ready! ***
.
Data used by the database server is stored in a Docker-managed volume called
mssql-volume
. This means you can safely stop (and even remove!) the container without
losing your data.
You can share files between your machine and the container by adding them to the src/
folder in this repository. You likely won't need to do this too often, because you can
connect to the database server using sqlcmd
from your machine, but we provide this just
in case.
By default, SQL Server comes with a user named sa
that with full permissions. It's a bad
practice to use this user, so the container will create a new user named dev
for you.
You'll still have all the permissions you need to do whatever you want with the database.
The container will automatically create the AdventureWorks sample database for you,
including all the tables and data using the files in adventure-works/
.
These files are a copy of the original files from (microsoft/sql-server-samples)[https://github.com/microsoft/sql-server-samples], with some modifications to make them work with SQL Server for Linux.
To run queries against the database:
USE AdventureWorks;
SELECT TOP 5 FirstName, LastName FROM Person.Person;
GO
Full Text Search is enabled in the container. You probably won't need to use it, but the AdventureWorks sample database makes use of it so why not? 🤷
You can customize the username and password for the dev
user by setting the DEV_USER
and SA_PASSWORD
environment variables in the docker-compose.yml
file.
services:
mssql:
# ...
environment:
- MSSQL_SA_PASSWORD=your-custom-password
- DEV_USER=your-custom-username
Caution
Your password must adhere to SQL Server's password policy or the container will fail to start. It should include at least 8 characters of at least three of these four categories: uppercase letters, lowercase letters, numbers and non-alphanumeric symbols.
If you want to use a different folder to share files between your machine and the container,
you can change the src/
folder in the docker-compose.yml
file.
services:
mssql:
# ...
volumes:
- /path/to/a/folder/on/your/machine:/src
If things aren't working, try restarting the container and see if that fixes it.
docker compose -p mssql restart