Running MSSQL Server in a local Docker container

If the MSSQL Server is not needed all the time on the workstation, we can run it in a Docker container. It allows us to easily upgrade the server version and shut it down when it is not used. To set up MSSQL Server in a Docker container we will follow the steps in Nawaz Dhandala’ excellent article at How to Run SQL Server in a Windows Docker Container

Install the Docker Desktop application from https://www.docker.com/products/docker-desktop/

Start the MSSQL Server

We will start the MSSQL server in a Docker container. This script sets up a volume for the database, so when the container is stopped, or destroyed, the data stays on the host’s hard drive. The detached mode keeps the container running in the background. We will use a Linux container, as it has smaller memory and CPU requirements, and runs faster. In the port argument the first number specifies the outside port, the second number the inside port. To run multiple MSSQL server instances on the same host, increment the first number to use a unique number, like 1434. In a terminal execute

docker run -d \
  --name sqlserver \
  -e "ACCEPT_EULA=Y" \
  -e "MSSQL_SA_PASSWORD=TheSA#Databas4ServerPassword" \
  -e "MSSQL_PID=Developer" \
  -p 1433:1433 \
  -v sqlserver-data:/var/opt/mssql \
  mcr.microsoft.com/mssql/server:2022-latest

Test the MSSQL server

To test the server from inside the container we can remote into the container to execute SQL commands from the command line.

# Remote into the MSSQL Server container and start the sqlcmd command line tool
docker exec -it sqlserver opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "TheSA#Databas4ServerPassword" -C

To test the server from the workstation, we can connect to it from outside. To test from the command line install the sqlcmd commadn line tool and execute

# Or install sqlcmd locally and connect to the mapped port
sqlcmd -S localhost,1433 -U sa -P "TheSA#Databas4ServerPassword"

Connect to the server

To connect to the server from Microsoft SQL Server Management Studio, use the following settings. This example shows how to specify the port in the server name field using a comma. If we use the default 1433 port, it is not necessary to include it in the server name.

Automated database initialization

If we use the MSSQL server mainly for testing it is very useful to script the database initialization. This way we can always recreate the entire data infrastructure by running a script.

Create a Dockerfile to build a custom image that includes the initialization script

# Dockerfile - to build an MSSQL Server image with automatic database setup
FROM mcr.microsoft.com/mssql/server:2022-latest

# Switch to the root user for file operations
USER root

# Create a directory in the image for the initialization scripts
RUN mkdir -p /docker-entrypoint-initdb

# Copy the SQL initialization scripts from the init-scripts subdirectory of the workstation
COPY ./init-scripts/ /docker-entrypoint-initdb/

# Copy the entrypoint wrapper script from the  current directory of the workstation
COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Switch back to the mssql user
USER mssql

# Environment variables with defaults
ENV ACCEPT_EULA=Y
ENV MSSQL_PID=Developer

# When the container starts. execute the entrypoint.sh bash script
ENTRYPOINT ["/entrypoint.sh"]

Create the entrypoint.sh bash script in the same directory to execute the initialization scripts

#!/bin/bash
# entrypoint.sh - Start the MSSQL Server and run the init scripts

# Start SQL Server in the background
/opt/mssql/bin/sqlservr &
SQLSERVER_PID=$!

# Wait for SQL Server to become available
echo "Waiting for SQL Server to start..."
for i in {1..60}; do
    /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$MSSQL_SA_PASSWORD" -C -Q "SELECT 1" > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        echo "SQL Server is ready."
        break
    fi
    sleep 1
done

# Run the initialization scripts in the docker-entrypoint-initdb subdirectory of the container
for script in /docker-entrypoint-initdb/*.sql; do
    if [ -f "$script" ]; then
        echo "Running $script..."
        /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$MSSQL_SA_PASSWORD" -C -i "$script"
    fi
done

echo "Initialization complete."

# Keep the container running by waiting on the SQL Server process
wait $SQLSERVER_PID

In the init-scripts subdirectory of the workstation create the SQL script to initialize the database and call it create-database.sql

-- init-scripts/01-create-database.sql
-- Create the application database
IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = 'MyDB')
BEGIN
    CREATE DATABASE MyDB;
END
GO

USE MyDB;
GO

-- Create tables
CREATE TABLE Tasks(
    Id INT PRIMARY KEY IDENTITY(1,1),
    TaskName NVARCHAR(50) NOT NULL UNIQUE,
    Description NVARCHAR(100) NOT NULL,
    CreatedAt DATETIME2 DEFAULT GETUTCDATE()
);
GO

CREATE TABLE Data(
    Id INT PRIMARY KEY IDENTITY(1,1),
    TaskId INT FOREIGN KEY REFERENCES Tasks(Id),
    Count INT NOT NULL,
    Status NVARCHAR(20) DEFAULT 'pending',
    CreatedAt DATETIME2 DEFAULT GETUTCDATE()
);
GO

Build the custom MSSQL Server image and run it

Execute the scrip in the directory where the Dockerfile is located

docker build -t myapp-sqlserver .

Run the custom container

docker run -d  --name myapp-db  -e "MSSQL_SA_PASSWORD=TheSA#Databas4ServerPassword"  -p 1433:1433  myapp-sqlserver

Using Kiro Sandbox to run AI Agents and MCP servers in a secure environment

MCP servers provide standardized tools for AI agents to access providers and services, like GitHub, AWS, Azure. If MCP servers run unchecked on the workstation, those have full access to the filesystem. MCP Servers can cause catastrophic disasters, like deleting all files form the hard drive.

Kiro provides a sandbox to securely run MCP Servers in an isolated environment. Credentials are stored outside of the sandbox, MCP Servers can only access them through Kiro.

To run Kiro and MCP Serves on the workstation install the Docker Desktop application from https://www.docker.com/products/docker-desktop/

For more information

See https://kiro.dev/

An interesting post on the Kiro demo at Supercharging Kiro with Docker Sandboxes and MCP Catalog

Using AgentCraft

Log into Claude CLI

As AgentCraft uses your Claude Pro or Max subscription, first, you need to log into Claude CLI.

  • Open a terminal in the project folder and start Claude CLI with
claude
  • In the Claude CLI enter
/login

Follow the instructions to authorize Claude CLI to use your Anthropic subscription and paste the token from the browser window into the CLI.

Run AgentCraft

  • In a terminal navigate to the project folder
  • Execute the command
npx @idosal/agentcraft

The AgentCraft UI opens in your default web browser

Approving actions

If Manual approval is selected in the lower right corner (the button is hidden behind the thick fancy border), AgentCraft will ask for approval.

To approve the action

  • In the Claude CLI press enter to move the process forward
  • Claude CLI will ask for permission and execute the command of AgentCraft

Installing Claude AI

Install the Claude CLI

In a terminal execute

irm https://claude.ai/install.ps1 | iex

The Claude Code installation will check your system path environment variable, and if missing it will ask you to add the following to it:

C:\Users\YOUR_USER_NAME.local\bin

Start Claude CLI

  • Open a terminal in the project folder
  • Execute
claude

Configure Claude AI

  • Select the look in the terminal light/dark mode
  • Select Claude account with subscription. You need at least the Pro subscription to use Claude Code.
  • The Claude authorization page opens in your default web browser.
  • Claude CLI displays the message
    Login successful. Press Enter to continue…

Installing AgentCraft

AgentCraft is an AI Orchestrator with Real Time Strategy Game user interface.

It uses Claude Code CLI to access your Pro or Max Claude agent subscription. It does not need to know any tokens or credentials. To use AgentCraft, first, you need start Claude CLI and uses its infrastructure to connect to Claude Code.

Install Claude Code CLI

See Installing Claude AI

Install Node.js

AgentCraft is a Node.js package it requires Node.js version 18 or higher from https://nodejs.org/en/download

Run AgentCraft

To run AgentCraft directly from the NPM registry, execute the command in a terminal. This will always run the latest available version without a need for update.

npx @idosal/agentcraft

This is an NPM package for running AI agents in your project folder. It allows them to interact with your local files in that location. The user interface opens in a your default web browser.

Advanced use cases

To start AgentCraft in the background

npx @idosal/agentcraft start -d

To stop the server in the background

npx @idosal/agentcraft stop

Cannot connect to local MSSQL Server from Node.js

The default MSSQL server installation only enables the Shared Memory network protocol for connection.

Node.js can only connect using TCP/IP protocol. The error message is

Failed to connect to localhost/…. Error: Failed to connect to localhost:1433 – Could not connect (sequence) Failed to connect to localhost:1433 – Could not connect (sequence) ConnectionError: Failed to connect to localhost:1433 – Could not connect (sequence)

Enable the TCP/IP protocol

To be able to connect to a local MSSQL Server from a Node.js application, we need to enable the TCP/IP protocol.

  • Open the SQL Server Configuration Manager as administrator
    Right-click the SQL Server Configuration Manager item in the start menu, select More, and click the Run as administrator option
  • In the SQL Server Network Configuration select Protocols for MSSQL SERVER, and double-click the TCP/IP option. Set the Enabled value to Yes
  • The dialog box reminds us to restart the MSSQL Server for the change to take effect

Restart the MSSQL Server

  • On the left side select SQL Server Services, right-click MSSQL Server and select Restart

GitHub Copilot Configuration settings

You may apply these configuration settings to enable useful features. Always read the documentation to see if these are safe and beneficial to you.

Copilot Memory

You can use Copilot Memory to remember repository context across Copilot agent interactions.

To store a memory start the prompt with “Remember: …”

More information on GitHub Copilot memories are at https://docs.github.com/en/copilot/how-tos/use-copilot-agents/copilot-memory

Generic memories for all projects

To store generic instructions, prompt:
Remember: Never make assumptions, if in doubt, ask clarifying questions

Project level memories

Memories are concise, actionable facts than Copilot agents will retain across sessions. To enable project level memories and allow agents to automatically save new discoveries in the .github/copilot-memory.md file prompt:
Create the memory file for agents

Project level instructions

To generate instructions for agents to avoid the repeated discovery of the entire project, we will create the .github/copilot-instructions.md file:

  • On the top of the chat window click the gear icon
  • Select Instructions & Rules
  • On the top of the screen select Generate agent instructions

Checkpoint file changes

chat.checkpoints.showFileChanges set to ON

Explain button

chat.editing.explainChanges.enabled set to ON

Inline Chat Enable V2

If you want to experiment with the new inline chat feature enable

inlineChat.enableV2

Usage suggestions

Hide Sessions

When the chat window is wide enough it displays the list of prior sessions. It is useful, but prevents us to widen the chat window for better reading experience. We can disable this behavior using the chat.viewSessions.enabled setting, or close the prior sessions with the Hide Agent Sessions Sidebar button

Kerbal Space Program 1 vs. 2

The development of Kerbal Space Program 2 was terminated prematurely, just at the time when the major bugs were removed, but before the application would provide significant benefits over version 1.

With mods, Kerbal Space Program 1 can provide the same visual quality with less bugs and better performance. As the development of version 1 was completed at a planned state, the application is stable, and will not change anymore. This simplifies the work of modders, who otherwise would need to constantly update their mods to keep up with the changes in the application code. This provides the ideal platform for the modding community to freely enhance the game for the benefit of everyone.

Visual Quality Improvements

Users recommend the following mods to improve visual quality

  • Scatterer (Kabrams Diamond Sunflare or any other mod available)
  • Parralax
  • EVE (Or if you’re willing to pay, Blackrack’s Volumetric Clouds)
  • PlanetShine
  • Firefly
  • Astronomer’s Visual Pack
  • Better Kerbol
  • ASET Props and Avionics packs
  • Textures Unlimited
  • TextureReplacer
  • Waterfall
  • WindowShine
  • ShineFix
  • TUFX

Determine the Azure Container App memory usage

To determine how much memory the Azure Container App needs, we can use the Metrics feature. To monitor the resource usage

  • Log into the Azure Portal at https://portal.azure.com
  • Open the Container Apps page, and select the application
  • On left in the Monitoring menu select Metrics
  • Click the Add metric button and select the Memory Working Set Bytes and Max value

Pass environment variables to Azure Container Apps

To pass secrets, configuration values to Azure Container Apps we can use the Azure CLI or the Azure Portal.

To pass an environment variable value to toe Azure Container App using the Azure CLI execute the command in a terminal

az containerapp update --name <app-name> --resource-group <rg> \
  --set-env-vars NODE_OPTIONS="--max-old-space-size=4096"

To use the Azure Portal web interface

  • Log into the Azure Portal at https://portal.azure.com
  • On the Container Apps page select the application
  • In the Application, Containers, page open the Environment variables tab and add a new environment variable. Click the Save as a new revision button