Reputation: 935
I am very new to docker and, although I'm getting used to the syntax simple things still elude me.
For my development environment I would like to run SQL Server 2017/19 as a container docker. I did a google search and found the following on the microsoft website:
"To run the container image with Docker, you can use the following command from a bash shell (Linux/macOS) or elevated PowerShell command prompt."
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=<YourStrong!Passw0rd>" `
-p 1433:1433 --name sql1 `
-d mcr.microsoft.com/mssql/server:2017-latest
If I would like to wrap that up in a simple dockerfile or docker-compose file how do I go about it?
Upvotes: 3
Views: 480
Reputation: 116
as a preface: you don't need a dockerfile or docker-compose in order to run a sql server instance for your development environment. If you just want quickly start your latest 2017 container just enter the comand you already found.
If you however want to easily store the command, not having to type it everytime, why not add a simple bat script to you folder.
Though, if you want to extend your docker image (e.g. install additional libraries) then you would need a dockerfile. Please also consult the docker documentation (great documentation) for how to do that. Or if you want to compose multiple docker instances (in order for them to easily communicate with each other) then a docker-compose file is the way to go.
But in order to actually answer your question: Create some folder with 2 files
folder
|__> DockerFile
|__> docker-compose.yml
The contents of your DockerFile would then be: (mind that this example here actually does nothing except pointing to the existing microsoft image, but if you use it without the docker-compose you can also define file mappings, password config etc. here and simply start a new container from this new pre-configured image)
FROM microsoft/mssql-server-windows-developer:2017
# environment configuration moved into docker-compose file
# EXPOSE 1433:1433
# ENV attach_dbs="[{'dbName':'YourDBName','dbFiles':['C:\\temp\\yourDB.mdf','C:\\temp\\yourDB_Log.ldf']}]"
# ENV ACCEPT_EULA=Y
# ENV sa_password=yourPassword
Then your docker-compose.yml might look like this:
version: '3'
services:
yourServiceName:
container_name: yourContainerName
build: .
ports:
- "1433:1433"
volumes:
- .:C:/temp/
environment:
sa_password: "yourPassword"
ACCEPT_EULA: "Y"
attach_dbs: "[{'dbName':'YourDBName','dbFiles':['C:\\\\temp\\\\yourDB.mdf','C:\\\\temp\\\\yourDB_Log.ldf']}]"
calling docker-compose up
in cml or PowerShell inside of the folder will start this new SQL-Server container.
Regardless i would recommend mapping the mdf and ldf files for easy access and e.g. for storing a state even if you shut down the docker image (if that is your desired behaviour).
Upvotes: 2
Reputation: 10757
docker-compose.yml:
version: "3.3"
services:
msql:
image: mcr.microsoft.com/mssql/server:2017-latest
environment: {
ACCEPT_EULA: "Y",
SA_PASSWORD: "<YourStrong!Passw0rd>"
}
ports:
- "1433:1433"
container_name: "sql1"
Upvotes: 0