Area: Optimizely CMS
Applies to versions: 12 and higher

Dockerize a CMS application

Recommended reading 
Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.

This example assumes you already have an Optimizely CMS ASP.NET Core-based application on your machine. The project in this example is called 'episerversample'). For more information, see Installing Optimizely.

If you are new to ASP.NET, you can follow a external-link.png simple tutorial to initialize a project or clone our external-link.png ASP.NET Docker Sample.

Create a Docker file for the application

  1. Create a Dockerfile in your project folder.
  2. Add the text below to your Dockerfile for either Linux or Windows Containers. The tags below are multi-arch, meaning they pull either Windows or Linux containers depending on what mode is set in external-link.png Docker Desktop for Windows. Read more in switching containers.

  3. The Dockerfile assumes that your application is called episerversample. Change the Dockerfile to use the DLL file of your project.

    FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build-env
    WORKDIR /app
    COPY *.csproj ./
    RUN dotnet restore
    COPY . ./
    RUN dotnet publish -c Release -o out
    FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim
    WORKDIR /app
    COPY --from=build-env /app/out .
    EXPOSE 80
    ENTRYPOINT ["dotnet", "episerversample.dll"]
  4. To make your build context as small as possible, add a external-link.png.dockerignore file to your project folder and copy the following into it.

Build and run the Docker image

  1. Open a command prompt and navigate to your project folder.
  2. Use the following commands to build and run your Docker image:
    docker build -t episerversample . 
    docker run -it -e "Urls=http://+:80" -p 8080:80 episerversample
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 02, 2021

Recommended reading