To enable working with custom images using the Sitecore CLI, we need to add Sitecore Management Services. Without this on the CM server, the CLI won't function. This guide covers container setup, while for other environments, please install via package.
![](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2Fd52Xmi4wl5SCq0SFyqdAt%2F2fbf91064691705a1c166b4650f890d8%2Fcustomimage21.png&w=3840&q=75)
Configuring Sitecore CLI
First, we will proceed to configure the Sitecore CLI so that it can be used in the current project. The detailed configuration procedure is described in the following page.
This time, we will execute the following commands in the project folder.
dotnet new tool-manifest
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
![customimage17.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F2kUk7ipbT4810wXAYjWHvb%2Ff9ddfbef6361ad40e2fcabe7b04c2084%2Fcustomimage17.png&w=3840&q=75)
Access Sitecore running in this state.
dotnet sitecore login --cm https://cm.sitecoredemojp.localhost/ --auth https://id.sitecoredemojp.localhost/ --allow-write true
![customimage18.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F4fKvvxYMAMRtWmIJgNPU5o%2F5e9ad27161ebf51506acb5cb18df5c8c%2Fcustomimage18.png&w=3840&q=75)
You have successfully logged in. Now we will update the schema with the following command
dotnet sitecore index schema-populate
However, an error is displayed. This error occurs when Sitecore Management Services is not installed.
![customimage19.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5E7nKyzEP1bszczs3B9Yz5%2F97820988ce498392a2c4e85af253336b%2Fcustomimage19.png&w=3840&q=75)
Installing Sitecore Management Service
In order to install the module, a definition to install the module must be added to the file docker\build\cm\Dockerfile in which the container image that will serve as the CM server is built. The reference for this module is as follows
This information will be put into the project's configuration file.
First add the following one line to your .env file. This is in the form of setting up an image repository.
MANAGEMENT_SERVICES_VERSION=4.2-1809
This just puts the definition in .env, so docker compose cannot determine which instance to put it in. This time, add a line to the docker-compose.override.yml file.
cm:
build:
args:
MANAGEMENT_SERVICES_IMAGE: ${SITECORE_MODULE_REGISTRY}sitecore-management-services-xm1-assets:${MANAGEMENT_SERVICES_VERSION}
Finally, update the docker\build\cm\Dockerfile file. This is also a direct reference to the code in the above reference.
ARG MANAGEMENT_SERVICES_IMAGE
FROM ${MANAGEMENT_SERVICES_IMAGE} as management_services
# Copy the Sitecore Management Services Module
COPY --from=management_services C:\module\cm\content C:\inetpub\wwwroot
Once the above settings are complete, build the cm image again.
docker-compose build cm
You now have an image with the Sitecore Management Service installed. Start the container.
docker-compose up -d
![customimage20.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F1AsslSnrZSSioTKQ72KOBu%2F5698e7a49192c184a7120b7b826eace2%2Fcustomimage20.png&w=3840&q=75)
After logging in, run the command to confirm that the module has been installed correctly. Note that if you have successfully logged in with the server name and other information last time, the server name and other information in the `.sitecore\user.json` file will be listed, so you can proceed simply by logging in.
dotnet sitecore login
dotnet sitecore index schema-populate
![customimage21.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2Fd52Xmi4wl5SCq0SFyqdAt%2F2fbf91064691705a1c166b4650f890d8%2Fcustomimage21.png&w=3840&q=75)
We have successfully accessed and controlled the Sitecore instance through the Sitecore CLI.
Summary
In this article, we showed you how to include Sitecore Management Services, which are required to use the Sitecore CLI, in your image. We have confirmed that once defined, they can be added relatively easily.