Edit Dockerfile for Your Linux 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:
Dockerfile
Dockerfiles can be customized to perform additional tasks. NCache Dockerfiles are placed at GitHub for the following:NCache Enterprise .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
/opt
.
You can get the installncache.sh scripts from GitHub for the following:
- ipbinding.sh
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:
- startup.sh
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 resources folder exists in the same directory as the Dockerfile.
- Dockerfile
- resources (folder)
- ipbinding.sh
- startup.sh
- installncache.sh
- ncache.ent.netcore.tar.gz
Customize Dockerfile
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 Enterprise 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 mcr.microsoft.com/dotnet/core/runtime:3.0
# 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 folder ("resources") 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 "resources" folder.
# Make sure that NCache Linux setup (.tar.gz) resides in the "resources" 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 .
# Exposing ports used by NCache for communication.
EXPOSE 8250 8251 9800 7800-7900 8300-8400 8260 10000-10100
# 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 ed -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.
# The parameter "--installmode" represents the NCache installation mode and has the following values:
# Enterprise Server Install mode = "0"
# Enterprise Remote Client Install mode = "3"
RUN chmod -R 775 /app &&\
./installncache.sh --firstname "John" --lastname "Smith" --email "john@alachisoft.com" --company "Alachisoft" --evalkey "xxxxxxxx" --installpath /opt --force --password "xxxxxxxx" --installmode 0
# Run activate.sh in /opt/ncache/bin/activate to activate licensing online using the license key obtained from sales@alachisoft.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 john@alachisoft.com
# Entry point for the container, once all the required configurations have been made.
ENTRYPOINT ["/app/startup.sh"]
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
ncache
with optional tagsenterprise-server-5.0
in the format <image_name>:<optional_tag>:
PS C:/Docker> docker build . –t ncache:enterprise-server-5.0
Note
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-enterprise-5.0.tar" ncache:enterprise-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.
See Also
Create Containers
Use NCache in Docker
NCache Docker on Windows Server