
I enjoy using SQL Server as my main database when building an app. As a .NET Developer, I usually pair SQL Server with .NET apps, because they’re so good together.
Most of the time I spend my time on Windows when developing a .NET app, which is surprisingly great because Visual Studio only available on Windows.
Even SQL Server is also optimized for Windows first. You got a complete set of tools there, including the SQL Server Management Studio.
But what if you want to run SQL Server on a cheap VPS, share it with other developers? You can start a Docker container that contains SQL Server database service and write the apps together using the same database instance from a dedicated VPS.
That’s why I write this post.
I want to give you a starter Docker Compose file to run SQL Server as a Docker container.
Because the official example given by Microsoft is just to run it with the docker CLI commands, which is unmaintainable.
SQL Server Docker Compose Structure
The Docker Compose structure for SQL Server is quite simple. You just need to prepare a compose file like the following template.
name: sql-server
services:
sql-server:
image: mcr.microsoft.com/mssql/server:<version>-latest
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=<password>Replace the <version> with the SQL Server version you want to run.
So far, you can choose between 2025, 2022, 2019, or 2017.
The ACCEPT_EULA environment variable needs to be written as Y, which means you agree to their license agreement.
Replace the MSSQL_SA_PASSWORD with your own super admin password.
This password will be used for the sa account.
The password should follow the SQL Server default password policy, which is at least 8 characters long and contains characters from three of the following four sets:
- uppercase letters
- lowercase letters
- base-10 digits
- symbols
If you don’t want to write down the password inside the Docker Compose file, which you should be, you can also set the environment variable in the .env file.
The .env file should be located in the same folder as the compose.yaml file.
Here’s an example of the .env content:
MSSQL_SA_PASSWORD=<password>Then don’t forget to put .env in .gitignore so you don’t accidentally push the MS SQL Password, even though it’s only for testing.
Once you’ve set everything, just go to the compose.yaml directory and run this command:
docker compose up -dThis will run the app as a Docker container in the background.
If you decide to take it down, you can run this command:
docker compose downSQL Server Docker Ready-to-use Compose Files
In this section, I have already prepared Docker Compose content that’s ready for you to copy.
You can just prepare a compose.yaml file, copy the content, and run the service.
But I suggest making some changes first, depending on your use case.
SQL Server 2025 Docker Compose Example
name: sql-server-2025
services:
sql-server-2025:
image: mcr.microsoft.com/mssql/server:2025-latest
container_name: sql-server-2025
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=<your-Strong-passw0rd>
restart: unless-stopped
volumes:
- sql-server-2025-volume:/var/opt/mssql
volumes:
sql-server-2025-volume:
name: sql-server-2025-volumeSQL Server 2022 Docker Compose Example
name: sql-server-2022
services:
sql-server-2022:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: sql-server-2022
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=<your-Strong-passw0rd>
restart: unless-stopped
volumes:
- sql-server-2022-volume:/var/opt/mssql
volumes:
sql-server-2022-volume:
name: sql-server-2022-volumeSQL Server 2019 Docker Compose Example
name: sql-server-2019
services:
sql-server-2019:
image: mcr.microsoft.com/mssql/server:2019-latest
container_name: sql-server-2019
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=<your-Strong-passw0rd>
restart: unless-stopped
volumes:
- sql-server-2019-volume:/var/opt/mssql
volumes:
sql-server-2019-volume:
name: sql-server-2019-volumeSQL Server 2017 Docker Compose Example
name: sql-server-2017
services:
sql-server-2017:
image: mcr.microsoft.com/mssql/server:2017-latest
container_name: sql-server-2017
ports:
- "1433:1433"
environment:
- ACCEPT_EULA=Y
- MSSQL_SA_PASSWORD=<your-Strong-passw0rd>
restart: unless-stopped
volumes:
- sql-server-2017-volume:/var/opt/mssql
volumes:
sql-server-2017-volume:
name: sql-server-2017-volumeFinal Thoughts
Other than copy-pasting from the template above, you can also get the same docker compose templates from GitHub.
Hope this simple post can help you run SQL Server on Linux, as simple as docker compose up -d.
As usual, if you have any questions or a better method, leave a comment below. Thanks for reading, and see you next time!