Streamline your development workflow by using Docker to stand up and run SQL Server instances quickly and without fuss.
In short however, Docker allows you to “spin-up” instances of applications, (e.g. SQL Server, Redis, etc.), really quickly without having to go through laborious, (and often confusing), installations. So from a developer perspective – it’s awesome – you can concentrate on coding, and not get side-tracking on installing an instance of SQL Server on Linux, (for example).
I picked SQL Server as the target app for this article for 2 reasons:
Now, (assuming you’ve installed Docker), type the following at the command line, (don’t worry I’ll take you through everything below):
Let's go through a docker run with SQL.
The “-e” flag is essentially an “Environment Flag”, which allows us to, (again not surprisingly), configure the Container Environment. In this particular case, we are specifying that we accept the End User Licensing Agreement, (EULA), for SQL Server by passing in a ‘Y’ value.
Another Environment Flag, this time we are setting up the Server Administrator, (SA), account for SQL Server. The SA account is, (as the name suggests), the local SQL Server Admin account – so be careful!
GOTCHA! You’ll need to provide a SA password that adheres to the SA Password Policy, otherwise the SQL Server instance will fail to run, (you’ll get a GUID returned, as the Container does run briefly, but will subsequently stop if a weak password is provided!).
Our final Environment flag, this one specifies the “flavour” of SQL Server, in this instance we’re passing in ‘Express’ as we only require the free version.
This is our “Port Mapping” flag, it maps the Containers “internal” port to an externally facing port on our local machine. Without this, we could not connect into our SQL Server Container instance. Here we are mapping the internal port 1433 to an external port of 1433, (note we could choose any unused “external” port).
The ‘-d’ flag tells Docker to run our Container in “detached mode”, so it kind of runs in the “background”, therefore we’ll get a prompt back at our command line.
The last part of this command is just the name of the image we want followed by the version we want, (image name and version are separated by a colon ‘:’).
Note: You’ll see that we are using the Ubuntu Linux image of SQL Server, (there are of course Windows versions available). I choose this version as Linux and Mac PC’s running Docker can only use “Linux Containers”. Only Windows PC’s can run both Windows and Linux Containers, so this was the more ubiquitous choice.
Launch VSCode and load the solution.
Select the extensions icon on the left and Install the Docker extension.
To start out with a fresh clean docker environment run the Docker Clean commands:
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
To run Docker Compose right click on the Docker Compose YML file and select "Compose Up"
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build
COPY ["MyOrchardCoreCMS.csproj", ""]
COPY ["NuGet.config", ""]
RUN dotnet restore "./MyOrchardCoreCMS.csproj"
COPY . .
RUN dotnet build "MyOrchardCoreCMS.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyOrchardCoreCMS.csproj" -c Release -o /app/publish
FROM base AS final
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyOrchardCoreCMS.dll"]
With your favorite browser, browse to localhost:8080.
Enter your site name, Select Blog for the recipe, select Sql Server for the database, enter the connection string credentials and then press the Finish Setup button.
Log into the Admin Dashboard by browsing to: localhost:8080/admin.
Enter your credentials and press the "Log in" button.
Now you have logged into the Admin Dashboard, You are ready to set started with Orchard Core CMS.
As a developer, I don’t want to waste time standing up the infrastructure to support my coding endeavors – I just want to code! So for me Docker is an excellent tool I use to streamline my development workflow.
The complete source code is located here.