Skip to content

Instantly share code, notes, and snippets.

@anton-dealmeida
Last active June 14, 2024 19:53
Show Gist options
  • Save anton-dealmeida/4caa4628a710e77632e686a11ca66844 to your computer and use it in GitHub Desktop.
Save anton-dealmeida/4caa4628a710e77632e686a11ca66844 to your computer and use it in GitHub Desktop.
Docker: SQL Server with mounted Volume

SQL Server with Docker

The following script will create a Docker container which will run SQL Server and assign a password for user 'sa' This container will mount my C:\SQL_DB directory which contains my .mdf and .ldf files, it will then make those available to my container in the /sql_data directory. I can then open SQL Server Management Studio and attach my mdf files and go nuts from there.

Pull the image version you would prefer

 # pulling the latest version here, 2017-latest an example of a more specific one.
 docker pull mcr.microsoft.com/mssql/server:latest

Run the container and mount local host volume into databases

  docker run -d \
  -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=_yourPassw0rd_" \
  -p 1433:1433 \
  -v C:\SQL_DB:/sql_data \
  --name sql mcr.microsoft.com/mssql/server:latest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment