Setting up Sitecore Docker Images

Sitecore Docker for Dummies

Part 2, Tossing Sitecore into some (Docker) containers

No subscription required

This is part 2 in a series about Sitecore and Docker.

Keep in mind that most everything I write in these posts is simplified in one way or another. I figure; you either know more than me already - in which case you have no use for these posts. Or you’re like me - just starting out - in which case I can tell you, I didn’t need to know so it’s likely you won’t need to know either.

Prerequisites

Assuming you’re done playing with WordPress, I figure it’s time to get busy with some Sitecore. Having read various other “Getting started with Docker/Sitecore” posts out there, let me start by making a few things clear that caught me when I first began my journey.

  • No service subscription is reqiured. Not to Docker Hub, not to Azure, not anywhere.
  • This will not eat up all your precious disk space.

There are a few things that are required however, and there’s nothing I can do about that.

  • You will need to be a certified Sitecore developer with access to download from https://dev.sitecore.net/.
  • You need a valid license.xml file for Sitecore
  • You need to have Git installed.

Some (very) basic theory - grossly simplified

Last post we asked Docker for some images (for MySql and WordPress) and we launched up our containers using these images. If I was to write in detail about what an image is, this would no longer be a For Dummies approach to Docker. So instead, think of images like this.

  • OS Layer (Operating System)
  • Web Server Layer
  • .NET Layer
  • Sitecore Base Layer
  • Sitecore XP Layer
  • Sitecore ContentDelivery Layer

Each image (layer) has a dependency up the chain and is the diff between the dependencies and it’s current state. So you have an OS layer (Windows, Linux, whatever) and you then pile on top of this to get to where you want. Not entirely unlike how you pile up stuff on your newly installec PC when you first boot it up.

Ok so it’s really nothing like that, but it works as an abstraction. And is good enough to move on with.

What may not have been obvious (because we didn’t actually care or need to know), is that when we did the WordPress example, there were dependencies involved. It’s not like MySql and WordPress can run entirely without some kind of host. I don’t actually know or care which exactly, but I’ll bet there was some Linux involved.

With Sitecore - as you know - Linux will not get us going. At least not fully. We need Windows images and containers, and for that we need to tell Docker to switch mode from it’s Linux default.

Find Docker Desktop in your taskbar and make it switch to Windows containers (already done in this screenshot). Docker will restart and that will be that.

Once switched, it should look like this

We also can’t download Sitecore images freely, like we could with WordPress. Bummer. I won’t get into this discussion here. But we’re going to have to build these images ourselves.

We’re now ready to build some Windows based images for Sitecore. So let’s get to it.

Building your own Sitecore images

Make no mistake, it is a significant amount of work, to configure and set up an environment to build these images. Fortunately for me and fortunately for us, there are already some enthusiastic community members doing a pile of this work for us. Give a shoutout to pbering and jeanfrancoislarente if you come across them for all the work they’ve just saved you from.

Open up your favourite command prompt and execute the following:

PS> git clone https://github.com/Sitecore/docker-images.git
PS> cd docker-images

A few words before you continue. This repository can build you Sitecore images for every version from 7.5 and up. I know, because that’s how I started :P And while that is all fine and well, it is likely

a) not necessary
b) too time consuming

So don’t do that. I don’t mean “have a bit of patience” type time consuming btw, I mean “1-2 days” time consuming. I don’t know exactly how long it takes to build the entire set of images, since I had to restart a few times. And I was also caught in the “you need a registry account” falsum so lots of time was spent waiting for pointless uploads.

Anyway. Pretty much all of the work is done for you. All you need to do, is set up a build script. Copy this, and paste it into a file you call .\build.ps1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Load module
Import-Module (Join-Path $PSScriptRoot "\modules\SitecoreImageBuilder") -Force
# Settings
$installSourcePath = (Join-Path $PSScriptRoot "\packages") # PATH TO WHERE YOU KEEP ALL SITECORE ZIP FILES AND LICENSE.XML, can be on local machine or a file share.
$registry = "local" ` # On Docker Hub it's your username or organization, else it's the hostname of your own registry.
$sitecoreUsername = "YOUR dev.sitecore.net USERNAME"
$sitecorePassword = "YOUR dev.sitecore.net PASSWORD"
$baseTags = "sitecore-*9.2*1903" # optional (default "*"), set to for example "sitecore-*:9.1.1*ltsc2019" to only build 9.1.1 images on ltsc2019/1809.
# Restore packages needed for base images, only files missing in $installSourcePath will be downloaded
SitecoreImageBuilder\Invoke-PackageRestore `
-Path (Join-Path $PSScriptRoot "\images") `
-Destination $installSourcePath `
-Tags $baseTags `
-SitecoreUsername $sitecoreUsername `
-SitecorePassword $sitecorePassword
# Build and push base images
SitecoreImageBuilder\Invoke-Build `
-Path (Join-Path $PSScriptRoot "\images") `
-InstallSourcePath $installSourcePath `
-Registry $registry `
-Tags $baseTags `
-PushMode "Never" # optional (default "WhenChanged"), can also be "Never" or "Always".
$variantTags = "sitecore-*:9.2*1903" # optional (default "*"), set to for example "sitecore-xm1-sxa-*:9.1.1*ltsc2019" to only build 9.1.1 images on ltsc2019/1809.
# Restore packages needed for variant images, only files missing in $installSourcePath will be downloaded
SitecoreImageBuilder\Invoke-PackageRestore `
-Path (Join-Path $PSScriptRoot "\variants") `
-Destination $installSourcePath `
-Tags $variantTags `
-SitecoreUsername $sitecoreUsername `
-SitecorePassword $sitecorePassword
# Build and push variant images
SitecoreImageBuilder\Invoke-Build `
-Path (Join-Path $PSScriptRoot "\variants") `
-InstallSourcePath $installSourcePath `
-Registry $registry `
-Tags $variantTags `
-PushMode "Never" # optional (default "WhenChanged"), can also be "Never" or "Always".

This is a slightly modified version of the original, found in the repository.

In all this, there are only 3 lines you need to modify.

1
2
3
$installSourcePath = "D:\Dropbox\Sitecore Versions"
$sitecoreUsername = "taylor@swift.com"
$sitecorePassword = "nomorecountrymusic"

Replace these variable values to fit your needs. Dump your license XML file into $installSourcePath, and put your Sitecore SDN user credentials (the account you can download with) into $sitecoreUsername and $sitecorePassword.

In this configuration, you’re set to build any and all Sitecore 9.2 versions and variants. That’ll do for now.

Let’s get this show on the road. (Make sure you have your license.xml in place)

PS> .\build.ps1

And off it goes. If there is interest, I could go into greater detail in a separate post about what happens now - but you don’t really need to worry much about it. Suffice it to say, the script now gets busy downloading Sitecore releases and building images based on them. It will pull in base images as neeeded (for windows and sql server and so on). Sit back and relax.

Depending on PC spec and network speed, this will take anywhere from 10 minutes to.. I guess an hour or so. Assuming you end up with green text, all is well and we’re ready to finally get to the good stuff.

Spinning up Sitecore for the first time

Right. The time for WordPress is over. Let’s do this. Thanks to the aforementioned Docker heroes, your hello world will be as effortless as previous examples. But instead of… yea… let’s go crazy and fire up a full scaled Sitecore XP. Complete with xconnect index processors and everything. Heck, let’s throw some SXA on it as well (which then obviously includes Sitecore PowerShell Extensions 5.0 and JSS 12).

Too much? not at all. Child’s play.

PS> cd '.\tests\9.2.0 rev. 002893\windowsservercore\'
PS> docker-compose -f docker-compose.xp.sxa.yml up

And your console is about to get very busy. It opens up like this.

1
2
3
4
5
6
7
8
9
Creating network "windowsservercore_default" with the default driver
Creating windowsservercore_sql_1 ... done
Creating windowsservercore_solr_1 ... done
Creating windowsservercore_xconnect-indexworker_1 ... done
Creating windowsservercore_xconnect_1 ... done
Creating windowsservercore_xconnect-automationengine_1 ... done
Creating windowsservercore_cd_1 ... done
Creating windowsservercore_cm_1 ... done
Attaching to windowsservercore_solr_1, windowsservercore_sql_1, windowsservercore_xconnect-indexworker_1, windowsservercore_xconnect_1, windowsservercore_xconnect-automationengine_1, windowsservercore_cm_1, windowsservercore_cd_1

Give it a short while if this is your very first run (might need a minute or two).

But don’t wait too long; “smiling asian lady” is waiting for you on http://localhost:44001. Go say hi 😎

If (when) you want to log into Sitecore itself, go to http://localhost:44001/sitecore and log in with the trusted admin/b credentials.

That’s it. No seriously. Well almost.

Just two small things to do; we need to get your Solr properly initialised. Open up Control Panel -> Indexing and execute the two following tasks:

  • Populate Solr Managed Schema (all indexes)
  • Indexing Manager -> Rebuild all indexes

A few extra things (encore)

Open up a new PowerShell (your old one is busy). A few commands of interest.

PS> docker container ls

Will give you a list of the XP instance containers you just brought to life.

1
2
3
4
5
6
7
8
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d0502d19b42 sitecore-xp-sxa-1.9.0-cd:9.2.0-windowsservercore-1903 "C:\\ServiceMonitor.e…" 8 minutes ago Up 8 minutes 0.0.0.0:44002->80/tcp windowsservercore_cd_1
adeddff07172 sitecore-xp-sxa-1.9.0-standalone:9.2.0-windowsservercore-1903 "C:\\ServiceMonitor.e…" 8 minutes ago Up 8 minutes 0.0.0.0:44001->80/tcp windowsservercore_cm_1
60e224e76a32 sitecore-xp-xconnect-automationengine:9.2.0-windowsservercore-1903 "C:\\AutomationEngine…" 8 minutes ago Up 8 minutes 80/tcp windowsservercore_xconnect-automationengine_1
8c35b0e12dc0 sitecore-xp-xconnect:9.2.0-windowsservercore-1903 "C:\\ServiceMonitor.e…" 8 minutes ago Up 8 minutes 80/tcp, 443/tcp windowsservercore_xconnect_1
10650711905b sitecore-xp-xconnect-indexworker:9.2.0-windowsservercore-1903 "C:\\IndexWorker\\XCon…" 8 minutes ago Up 8 minutes 80/tcp windowsservercore_xconnect-indexworker_1
f9f3c36dc49b sitecore-xp-sxa-1.9.0-solr:9.2.0-nanoserver-1903 "cmd /S /C Boot.cmd …" 8 minutes ago Up 8 minutes 0.0.0.0:44011->8983/tcp windowsservercore_solr_1
40460ae5a753 sitecore-xp-sxa-1.9.0-sqldev:9.2.0-windowsservercore-1903 "powershell -Command…" 8 minutes ago Up 8 minutes (healthy) 0.0.0.0:44010->1433/tcp windowsservercore_sql_1

None of these containers have any sort of UI. But you can connect to the SQL server using SMSS as if it was any other SQL server. You can browse to http://localhost:44002 to find your CD server. You can even start a PowerShell inside it. Grab the CONTAINER ID for sitecore-xp-sxa-1.9.0-cd:9.2.0-windowsservercore-1903 and do

PS> docker exec -it 8d0502d19b42 powershell (replace with your own id)

And off you go.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\> dir
Directory: C:\
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 9/14/2019 2:18 PM inetpub
d-r--- 9/14/2019 11:35 AM Program Files
d----- 9/14/2019 11:35 AM Program Files (x86)
d----- 9/11/2019 12:00 AM RoslynCompilers
d----- 9/14/2019 2:18 PM Sitecore
d-r--- 9/10/2019 11:58 PM Users
d----- 9/10/2019 11:56 PM Windows
-a---- 3/19/2019 7:54 AM 5510 License.txt
-a---- 9/10/2019 11:59 PM 172328 ServiceMonitor.exe
PS C:\>

(a look inside your CD container)

PS> exit when you want to return to your host PowerShell session.

Once you’re ready to let go, you can tear all of this down again. Type in:

PS> docker-compose -f .\docker-compose.xp.sxa.yml down

And Docker will proceed to tear down all the containers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Stopping windowsservercore_cd_1 ... done
Stopping windowsservercore_cm_1 ... done
Stopping windowsservercore_xconnect-automationengine_1 ... done
Stopping windowsservercore_xconnect_1 ... done
Stopping windowsservercore_xconnect-indexworker_1 ... done
Stopping windowsservercore_solr_1 ... done
Stopping windowsservercore_sql_1 ... done
Removing windowsservercore_cd_1 ... done
Removing windowsservercore_cm_1 ... done
Removing windowsservercore_xconnect-automationengine_1 ... done
Removing windowsservercore_xconnect_1 ... done
Removing windowsservercore_xconnect-indexworker_1 ... done
Removing windowsservercore_solr_1 ... done
Removing windowsservercore_sql_1 ... done
Removing network windowsservercore_default

Done 😎 No resdiual Solr installs, no leftover databases, no resources being consumed. It’s gone (sort of, more on that next time), until you call it all up again :-)

I think that’s enough for now. Until next time.

Share