5

I want to alleviate memory issues I'm having with my containerized SQL Server. I'm running this on Windows 10, v 1709.

For testing, I created a SQL Server container with this command:

docker run -d -p 1433:1433 --name sql1 -e SA_PASSWORD=1Secure*Password1 
-e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer:2017-latest

Within this containerized SQL instance I created a database that worked until it became too large. I'm now getting insufficient memory errors. For example, when I run a query in SSMS I receive "There is insufficient system memory in resource pool 'default' to run this query." Likewise, when I check the SQL Server ring-buffer, I see RESOURCE_MEMPHYSICAL_LOW. When I get these errors, only 8 gigs of my laptop's available 16 gigs of RAM are in use. So this is not an issue with real physical memory.

Docker for Windows, when on Windows 10, runs containers in a Hyper-V VM which defaults to 1GIG of RAM. I can confirm this by starting my container, and then entering an interactive mode with it:

PS C:\repos\somefolder> docker exec -it sql1 powershell

Within interactive mode, following this other SO example, I see these results:

PS C:\> systeminfo | findstr "Memory"
Total Physical Memory:     1,023 MB
Available Physical Memory: 221 MB
Virtual Memory: Max Size:  1,023 MB
Virtual Memory: Available: 82 MB
Virtual Memory: In Use:    941 MB

Also, when I run docker stats I can see that my sql1 container is using PRIV WORKING SET in the range of 750MiB to 970MiB.

Ok, so I've clearly confirmed that I've got a Hyper-V VM 1GB limit I need to raise.

How do I do this, without losing the database that is inside this container? I see an answer that says "use -m" option, but I think that only works when the container is first being created.

Docker Version

$ docker version
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:12:48 2018
 OS/Arch:      windows/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.24)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:21:42 2018
  OS/Arch:      windows/amd64
  Experimental: false
Community
  • 1
  • 1
Brent Arias
  • 29,277
  • 40
  • 133
  • 234

1 Answers1

0

The SQL Server images allow you to attach databases in a JSON set as the attach_dbs environment variable.

What I've done is something like this:

# escape=` 

FROM microsoft/mssql-server-windows-express:2017-GA 

LABEL MAINTAINER="Seba Gómez @sebagomez"

# SQL Databases
COPY data\ c:/data
ENV attach_dbs="[{'dbName':'MyDB','dbFiles':['C:\\data\\MyDB.mdf','C:\\data\\MyDB_log.ldf']}, {'dbName':'MyOtherDB','dbFiles':['C:\\data\\MyOtherDB.mdf','C:\\data\\MyOtherDB_log.ldf']}]" `
    ACCEPT_EULA=Y `
    sa_password="dbPassword!"

All the mdf and ldf files are in a data folder right next to my dockerfile.

sebagomez
  • 9,501
  • 7
  • 51
  • 89