Containers: Create a Custom Container

Creating a custom container is where things get truly exciting. There’s actually a ton of work and knowledge around this. To start with, I’m going to keep it simple. I’m going to create a container with a database & some data and a couple of general customizations. From that, we’ll create our own container.

To understand why I’ve got a series on containers, read here.

Setting Up a Custom Container

To start with, I’m going to spin up a container with nothing fancy:

docker run -e 'ACCEPT_EULA=Y' `
    -e 'SA_PASSWORD=$cthulhu1988' `
    -p 1433:1433 `
    --name DockerDemoTemplate `

With this running, let’s connect up and make some changes:

USE master;

CREATE DATABASE CustomContainer;

USE CustomContainer

CREATE TABLE dbo.CustomTable
CustomValue varchar(50) NOT NULL);

INSERT dbo.CustomTable
('Move '),
('this '),
('to '),
('a '),
('new '),

EXEC sp_configure 'show advanced options', 1 ;  
EXEC sp_configure 'cost threshold for parallelism', 50 ;  

With that in place, let’s shut down the container and create an image:

docker stop DockerDemoTemplate

## create an image
docker commit DockerDemoTemplate dockerdemoimage

That’s it. Now it’s time to test it.

Consuming a Custom Container

Now, it’s just a question of treating it like a regular image, but, remembering that it’s local. The call looks like this:

docker run -e 'ACCEPT_EULA=Y' `
    -e 'SA_PASSWORD=$cthulhu1988' `
    -p 1433:1433 `
    --name DockerDemoCustomContainer `
    -d dockerdemoimage

That will fire up the image and you’ll find that the server settings, databases, and everything have migrated with it. This makes the image bigger, so it’s not something you’d want to do with large amounts of data.


There are much more sophisticated ways to get this done using Docker Files. However, this illustrates the point quite simply. You can customize your servers and then use those customizations. You don’t have to re-customize every time. Again, this is just a small slice of why containers are so powerful.

I hope the week of introductory posts on containers gave you enough information to get started on your own. There’s so much more to learn here. I think you, and I, have to spend some time understanding this technology better in order to appropriately use it. I plan to spend the time.

Want some precons? I’ve got ’em coming up. Query Tuning and DevOps both. Check it out:

SQLSaturday Columbus Precon, June 7 2019, Columbus OH
SQLSaturday Indianapolis Precon, Friday August 16th, 2019. Click here now to register.
SQLSaturday Oslos Precon, Friday August 30th, 2019. Click here to register.

3 thoughts on “Containers: Create a Custom Container

Please let me know what you think about this article or any questions:

This site uses Akismet to reduce spam. Learn how your comment data is processed.