Edit Dockerfile for Your Environment
NCache also provides Dockerfiles and supporting resources on GitHub to allow more flexibility while using NCache as a Docker image. You can customize the Dockerfile to create images and containers according to your requirements, and use NCache as a result.
What does NCache Dockerfile contain?
The Dockerfiles provided by NCache at https://github.com/Alachisoft/NCache-Docker contain commands to build images for NCache.
Note that to create the image from this file, the following resources are required:
NCache Open Source .NET Core setup file
This is a .tar.gz file. Download from Alachisoft’s website here.
installncache.sh The installncache.sh script extracts the NCache tar.gz and installs NCache in evaluation mode at the installation path
You can get the installncache.sh script from GitHub for the following:
The ipbinding.sh script changes the IP in the NCache configuration files. Hence, it is highly recommended that the IPs provided are static, as all future connections will take place using this IP. In case dynamic IPs have been assigned, the container might be assigned with a new IP (on the next connection) instead of the one stored in the configuration during container creation. This results in NCache service not starting.
You can get the ipbinding.sh scripts from GitHub for the following:
The startup script calls ipbinding.sh which replaces the IP with the actual IP assigned to the container on the first time the container is started. Furthermore, the startup.sh script starts ncached, ncacheloaderd and ncachebridged daemon services.
You can get the startup.sh scripts from GitHub for the following:
These resources must be placed in the following file structure (as also arranged in GitHub). Make sure that the 2 folders ("resources" and "setup") exist in the same directory as the Dockerfile.
- resources (folder)
- setup (folder)
You can customize the Dockerfile to perform any additional tasks after or before installation.
The following sample Dockerfile has been customized to specify credentials for dummy user John Smith while installing Cache Server edition for NCache Open Source Linux. It then executes a custom script to activate licensing for NCache using the activate.sh script, once installation has been completed.
# Setting base image for NCache. FROM microsoft/dotnet:2.2-runtime # Setting the enviornment variable so the NCache install script knows that it's running inside a container. ENV container ncachedocker # Setting work directory to copy setups and resources for configuring NCache. WORKDIR /app # Make sure that the 2 folders ("resources" and "setup") exist in the same directory as the Dockerfile. # Make sure that "ipbinding.sh" script resides in the "resources" folder. # Make sure that "startup.sh" script resides in the "resources" folder. # Make sure that "installncache.sh" script resides in the "setup" folder. # Make sure that NCache Linux setup (.tar.gz) resides in the "setup" folder. It can be downloaded from http://www.alachisoft.com/download-ncache.html. # Copying resources and setups into the work directory of the container. COPY resources . COPY setup . # Exposing ports used by NCache for communication. # Exposing the port at which Ncache service will listen for the incoming client connection requests. EXPOSE 9800 # Exposing the port at which Ncache service will listen for the incoming management connection requests (NCache Web Manager, Monitor and Tools). EXPOSE 8250 # Make sure your machine has access to internet for installation of packages. # Installing package procps (Prerequisite of NCache services). RUN apt-get update &&\ apt-get install procps -y # Installing NCache Linux setup (.tar.gz). # The parameter "--evalkey" is the install key and is sent to user through e-mail once they download NCache setup. In case if user does not get a key, contact us at http://www.alachisoft.com/company/contact-us.html. # The parameter "--firstname" represents the first name of the user. # The parameter "--lastname" represents the last name of the user. # The parameter "--email" represents the e-mail address of the user. # The parameter "--installpath" represents the path where ncache will be installed. If not provided then /opt/ncache will be used. # The parameter "--force" Force create destination directory if provided directory does not exist. # The parameter "--password" represents the password for user ncache. RUN chmod +x installncache.sh &&\ ./installncache.sh --firstname "John" --lastname "Smith" --email "firstname.lastname@example.org" --installpath "/opt" --force --password "xxxxxxxx" # Currently, the IP during NCache installation is stored in the configuration files and it can not be made static at that point. # However, the IP can be made static once the container is started. # The startup script calls ipbinding.sh which replaces the IP with the actual IP assigned to the container on the first time the container is started. # Furthermore the startup.sh script starts ncached daemon service. # Making startup.sh executable. RUN chmod +x /app/startup.sh # Run activate.sh in /opt/ncache/bin/activate to activate licensing online using the license key obtained from email@example.com. You can also manually activate the licensing by specifying the "/m" switch. # Pre-requisites for this are Internet connectivity and DNS Resolution. RUN /opt/ncache/bin/activation/activate -k XXXXXXXX-XXXXXX-XXXXXXXX -f john -l smith -e firstname.lastname@example.org # Entry point for the container, once all the required configurations have been made. ENTRYPOINT /app/startup.sh && bash
Create Images using Customized Dockerfile
Using this customized Dockerfile, you can now create Docker images which will host NCache as specified in Dockerfile.
Go to the relative path where the Dockerfile is placed. In the following examples, it is assumed it is placed in location C:/Docker.
The following docker build command creates image
ncachewith optional tags
opensource-server-5.0in the format <image_name>:<optional_tag>:
PS C:/Docker> docker build . –t ncache:opensource-server-5.0
To verify image has been created, run the command
docker images which lists all images and their details.
Save Image to Disk
Once an image is created, you can save it to the disk as a TAR file using docker save. The following commands save the images to the location myLocation with the same image name:
docker save -o "[myLocation]\ncache:server-opensource-5.0.tar" ncache:opensource-server-5.0
You can create containers using these images and proceed to use NCache. Note that for this, the image name should be the same as stored locally.