Sitecore 10 with Docker – Create a solution from the scratch – Add Modules and enable Sitecore Serialization

  1. Sitecore 10 with Docker – Create a solution from the scratch – Setting up the first docker instance
  2. Sitecore 10 with Docker – Create a solution from the scratch – Setup Sitecore 10.3 XM setup with custom images
  3. Sitecore 10 with Docker – Create a solution from the scratch – Add Modules and enable Sitecore Serialization
  4. Sitecore 10 with Docker – Create a solution from the scratch – Create solution and enable Sitecore Serialization
  5. Sitecore 10 with Docker – Create a solution from the scratch – Add ASP.NET Rendering Host and configure SXA-JSS

Add Sitecore Modules: PowerShell Extensions, Experience Accelerator, Managed Services

We want to use SXA-JSS in connection with ASP.NET rendering host. Therefore we need to install some modules on Sitecore to make it possible. You can find available default modules from Sitecore here

Let’s start with SPE & SXA

Add SPE & SXA

Please remember: At the beginning we added some environment variables to our .env file.

We will use now the following:

SITECORE_MODULE_REGISTRY=scr.sitecore.com/sxp/modules/
SPE_VERSION=6.4-1809
SXA_VERSION=10.3-1809

Add SPE & SXA to CM

In our docker-compose.override.yml file in the CM section we add following parameters

args:
        BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-cm:${SITECORE_VERSION}
        SPE_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-spe-assets:${SPE_VERSION}
        SXA_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-sxa-xm1-assets:${SXA_VERSION}

We open the docker file for CM and add the additional parameters so that the file content looks as following

ARG BASE_IMAGE
ARG SXA_IMAGE
ARG SPE_IMAGE

FROM ${SPE_IMAGE} as spe
FROM ${SXA_IMAGE} as sxa
FROM ${BASE_IMAGE}


# Set working direction
WORKDIR C:\inetpub\wwwroot

# Add SPE module
COPY --from=spe \module\cm\content .\

# Add SXA module
COPY --from=sxa \module\cm\content .\
COPY --from=sxa \module\tools \module\tools
RUN C:\module\tools\Initialize-Content.ps1 -TargetPath .\; `
    Remove-Item -Path C:\module -Recurse -Force;

Add SPE & SXA to MsSql

We will now introduce a new custom image for our docker.compose.override.yml

We add

  mssql-init:
    image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-xm1-mssql-init:${VERSION:-latest}
    build:
      context: ./docker/build/mssql-init
      args:
        BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-mssql-init:${SITECORE_VERSION}
        SPE_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-spe-assets:${SPE_VERSION}
        SXA_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-sxa-xm1-assets:${SXA_VERSION}

In this custom image we will prepare our SQL image to install the necessary stuff for our modules.

So the next step is to edit the DockerFile to use the new parameters.

# escape=`
ARG BASE_IMAGE
ARG SXA_IMAGE
ARG SPE_IMAGE

FROM ${SPE_IMAGE} as spe
FROM ${SXA_IMAGE} as sxa
FROM ${BASE_IMAGE}

COPY --from=sxa \module\db \sxa_data
COPY --from=spe C:\module\db C:\resources\spe

Add SPE & SXA to Solr

We start again modifying the docker.compose.override.yml and add a SXA_IMAGE parameter to the solr-init custom image configuration

  # Mount our Solr data folder and use our retagged Solr image.
  # Some modules (like SXA) also require additions to the Solr image.
  solr-init:
    image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-xm1-solr-init:${VERSION:-latest}
    build:
      context: ./docker/build/solr-init
      args:
        BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-solr-init:${SITECORE_VERSION}
        SXA_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-sxa-xm1-assets:${SXA_VERSION}

To our solr-init Dockerfile we add for SXA following

# escape=`
ARG BASE_IMAGE
ARG SXA_IMAGE

FROM ${SXA_IMAGE} as sxa
FROM ${BASE_IMAGE}

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Add SXA module
COPY --from=sxa C:\module\solr\cores-sxa.json C:\data\cores-sxa.json

BUILDING THE CUSTOM IMAGES

We have until now not really used our DockerFiles. We have already done a build in previous steps for our Vanilla instance, but we want now to build our custom images with the included modules.

To take full advantage of our DockerFile configuration and to install the modules we just added we have to build our custom images, with

docker-compose build

We can run following from PowerShell

docker-compose down 
./clean.ps1 
docker-compose build
docker-compose up -d

and visit sitecore

Enable Headless Services

Now that we have our first modules ready we will do the same for the headless services.

We are using following parameters from our .env file

HEADLESS_SERVICES_VERSION=21.0-1809
MANAGEMENT_SERVICES_VERSION=5.1.25-1809

We add following parameters to mssql-init, cm & cd in docker-compose.override.yml

HEADLESS_SERVICES_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-headless-services-xm1-assets:${HEADLESS_SERVICES_VERSION}

and additionally to our cm custom image in docker-compose.override.yml configuration the management service image

MANAGEMENT_SERVICES_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-management-services-xm1-assets:${MANAGEMENT_SERVICES_VERSION}

Resulting to following:

  mssql-init:
    image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-xm1-mssql-init:${VERSION:-latest}
    build:
      context: ./docker/build/mssql-init
      args:
        BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-mssql-init:${SITECORE_VERSION}
        SPE_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-spe-assets:${SPE_VERSION}
        SXA_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-sxa-xm1-assets:${SXA_VERSION}
        HEADLESS_SERVICES_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-headless-services-xm1-assets:${HEADLESS_SERVICES_VERSION}


.
.
.
  cd:
    image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-xm1-cd:${VERSION:-latest}
    build:
      context: ./docker/build/cd
      args:
        BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-cd:${SITECORE_VERSION}
        SXA_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-sxa-xm1-assets:${SXA_VERSION}
        HEADLESS_SERVICES_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-headless-services-xm1-assets:${HEADLESS_SERVICES_VERSION}

.
.
.
  cm:
    image: ${REGISTRY}${COMPOSE_PROJECT_NAME}-xm1-cm:${VERSION:-latest}
    build:
      context: ./docker/build/cm
      args:
        BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}sitecore-xm1-cm:${SITECORE_VERSION}
        SPE_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-spe-assets:${SPE_VERSION}
        SXA_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-sxa-xm1-assets:${SXA_VERSION}
        HEADLESS_SERVICES_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-headless-services-xm1-assets:${HEADLESS_SERVICES_VERSION}
        MANAGEMENT_SERVICES_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-management-services-xm1-assets:${MANAGEMENT_SERVICES_VERSION}

After adding our parameters for our custom images we need to adjust our DockerFiles as following

CD

# escape=`
ARG BASE_IMAGE
ARG SXA_IMAGE
ARG HEADLESS_SERVICES_IMAGE

FROM ${SXA_IMAGE} as sxa
FROM ${HEADLESS_SERVICES_IMAGE} AS headless_services
FROM ${BASE_IMAGE}


SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

# Copy development tools and entrypoint
COPY --from=tooling \tools\ \tools\

WORKDIR C:\inetpub\wwwroot

# Add SXA module
COPY --from=sxa \module\cd\content .\
COPY --from=sxa \module\tools \module\tools
RUN C:\module\tools\Initialize-Content.ps1 -TargetPath .\; `
    Remove-Item -Path C:\module -Recurse -Force;

# Copy and init the JSS / Headless Services Module
COPY --from=headless_services C:\module\cd\content C:\inetpub\wwwroot
COPY --from=headless_services C:\module\tools C:\module\tools
RUN C:\module\tools\Initialize-Content.ps1 -TargetPath C:\inetpub\wwwroot; `
    Remove-Item -Path C:\module -Recurse -Force;

MSSQL-INIT

# escape=`
ARG BASE_IMAGE
ARG SPE_IMAGE
ARG HEADLESS_SERVICES_IMAGE

FROM ${HEADLESS_SERVICES_IMAGE} AS headless_services
FROM ${SPE_IMAGE} as spe
FROM ${BASE_IMAGE}


COPY --from=spe C:\module\db C:\resources\spe
COPY --from=headless_services C:\module\db C:\jss_data

CM

# escape=`

ARG BASE_IMAGE
ARG SXA_IMAGE
ARG SPE_IMAGE
ARG MANAGEMENT_SERVICES_IMAGE
ARG HEADLESS_SERVICES_IMAGE

FROM ${SPE_IMAGE} as spe
FROM ${SXA_IMAGE} as sxa
FROM ${HEADLESS_SERVICES_IMAGE} AS headless_services
FROM ${MANAGEMENT_SERVICES_IMAGE} AS management_services
FROM ${BASE_IMAGE}


WORKDIR C:\inetpub\wwwroot

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
COPY --from=spe \module\cm\content .\

COPY --from=sxa \module\cm\content .\
COPY --from=sxa \module\tools \module\tools
RUN C:\module\tools\Initialize-Content.ps1 -TargetPath .\; `
    Remove-Item -Path C:\module -Recurse -Force;

# Copy the Sitecore Management Services Module
COPY --from=management_services C:\module\cm\content C:\inetpub\wwwroot

# Copy and init the JSS / Headless Services Module
COPY --from=headless_services C:\module\cm\content C:\inetpub\wwwroot
COPY --from=headless_services C:\module\tools C:\module\tools
RUN C:\module\tools\Initialize-Content.ps1 -TargetPath C:\inetpub\wwwroot; `
    Remove-Item -Path C:\module -Recurse -Force;

In PowerShell we can call now

docker-compose down
./clean.ps1
docker-compose build
docker-compose up -d

to build our custom images and spin up sitecore with Headless Services & Managed Services installed.

Notice: If you get an error stating “services.id must be a mapping” or similar you need to check the formatting of your docker-compose.override.yml.

Install Sitecore CLI

Now we will install the Sitecore CLI and connect to Sitecore

In PowerShell we go to our root folder and install & init the CLI

dotnet new tool-manifest
dotnet nuget add source -n Sitecore https://sitecore.myget.org/F/sc-packages/api/v3/index.json
dotnet tool install Sitecore.CLI 
dotnet sitecore init
dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.Serialization
dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.Publishing

More information can be found under https://doc.sitecore.com/xp/en/developers/101/developer-tools/install-sitecore-command-line-interface.html

Now we will authenticate against our Sitecore instance.

The command to login we use will be

dotnet sitecore login --authority https://<sitecore-identity-server> --cm https://<sitecore-instance> --allow-write true

We can find the parameters in our .env file

CM_HOST=cm.mydockerexperience.localhost
ID_HOST=id.mydockerexperience.localhost

In PowerShell we invoke

dotnet sitecore login --authority https://cm.mydockerexperience.localhost --cm https://id.mydockerexperience.localhost --allow-write true

A new browser windows opens asking you for your credentials. On the following window click yes

Return to PowerShell and see that you have been logged in successfully

A user.json has been created and your credentials have been saved

In our next part we will create a solution to be able to code and publish to our container

2 Pingbacks

Leave a Comment

Your email address will not be published. Required fields are marked *