Running Microsoft SQL database server with Docker
Recently I have started upgrading self with some docker skills. So, here is how, you can run and use a Microsoft SQL server on your computer.
The first step is to go ahead and create a folder. I tend to create a separate folder for every new container I wish to run. it seems to work better for me.
Then, create a file called, docker-compose.yml. The file name is important for the command to work as per my steps.
version: '3.8'
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: sqlserver
environment:
ACCEPT_EULA: "Y"
MSSQL_SA_PASSWORD: "YourStrong!Passw0rd"
ports:
- "1433:1433"
volumes:
- sqlserverdata:/var/opt/mssql
volumes:
sqlserverdata:
What is happening here? we are setting up a service with the name, ‘sqlserver’. the image ‘mcr.microsoft.com/mssql/server:2022-latest’ will be pulled from the Docker container registry.
Now, time for some additional commands and settings. we need to supply the password. then, of course, the default ports. finally, I want the microsoft sql data to be preserved between different container runs.
Now, I simply need to run the following command in the terminal, and it will get the container pulled and up and running on the local machine.
docker-compose up -d
Now, we can use SQL Management Studio to connect to this database.
and, it’s working just fine.
the full code is here on my github.
That’s all there is to it.
I work as a coding tutor. You can hire me on Upwork, Fiverr and Codementor. You can also book a session on calendly, and visit my website. Also, video tutorials on my YouTube Channel.