Docker is an open platform for developing, shipping, and running applications. It can significantly reduce the delay between writing code and running it in production. This is because Docker Containers are lightweight and contain everything needed to run an application within them.
NCache is an extremely fast in-memory distributed cache that also provides Docker images for both Windows Server and Linux. In this blog, I’ll explain how you can configure and use these images so that you may start using NCache ASAP!
NCache in Docker
Docker Images are self-contained, meaning that these images contain everything required to run the application within them. The user just has to pull these images, create containers, and use them.
This also applies to the NCache Docker Images. This means that by using NCache with Docker, you save yourself the hassle of having to download and install each and everything required by NCache. With Docker, you just need to pull the respective image that you need, make some configuration changes, and you are good to go.
Deploying NCache Docker Image
Deploying NCache Docker Image(s) is a pretty straightforward process. In this section, I’ll show you how to configure, deploy, and use the NCache Docker Image in a Linux environment. This process is the same for the NCache Docker Image for Windows just replace the image name where necessary.
Step 1: Configure Network
Firstly, you’ll need to create a custom network in Docker so that you can assign static IP addresses to your containers. This is done to tackle the problem of your containers changing their IP address after you restart them or when the host machine restarts. The following command creates a custom Docker network with an IP range and the name nbrg.
sudo docker network create --subnet=172.19.0.0/16 --gateway=172.19.0.1 nbrg
Step 2: Pull Image and Create Containers
After you have configured the network, you need to pull the NCache Docker Image from the Docker Hub repository. Execute the following command to pull this image:
docker pull alachisoft/ncache:enterprise-server-linux-latest
Once you have created a custom Docker network and pulled the NCache Docker Image, you’ll have to create containers that host NCache. The docker run or docker create commands create these containers. The difference between the two is that the former also starts the container after creating it.
Depending on your Docker Container Deployment Scenario, the process of creating and running your containers will vary. In this scenario, your containers and host both are Linux-based.
The following two commands create and start the containers named ncache-ent-server-01 and ncache-ent-server-02 with the custom Docker network nbrg that we created in the previous step. A static IP address is also assigned to each container.
docker run --name ncache-ent-server-01 --net nbrg --ip 172.19.0.11 -itd alachisoft/ncache:enterprise-server-linux-latest
docker run --name ncache-ent-server-02 --net nbrg --ip 172.19.0.12 -itd alachisoft/ncache:enterprise-server-linux-latest
Step 3: Connect to the Container
You’ll need to connect to the containers that you created to start working with them. The following command connects you to the container (running) named ncache-ent-server-01 and opens a PowerShell instance within it.
docker exec -it ncache-ent-server-01 pwsh
Step 4: Activate License
By default, the NCache Docker containers are not activated. So, to use these containers, you’ll either have to register/activate them using a license key (obtained from email@example.com) or you’ll have to register them for evaluation by using an evaluation key.
To use the NCache PowerShell cmdlets, you need to import the NCache PowerShell module. The following command imports the NCache PowerShell module inside the container ncache-ent-server-01.
Once you have imported the NCache PowerShell module inside the container ncache-ent-server-01, you can use the NCache PowerShell cmdlets to register NCache. The following command registers NCache using the activation key with the environment set to production and the number of clients set to 4 inside the container ncache-ent-server-01.
Register-NCache -Key xxxxxxxx-xxxxxx-xxxxxxxx -FirstName John -LastName Smith -Email firstname.lastname@example.org -Company your_company_name -Environment production -Clients 4
If you want to evaluate NCache before purchasing a license for it, you try NCache for a free 60 day trial period by registering NCache for evaluation using an evaluation key. The following command registers NCache for evaluation with the evaluation key inside the container ncache-ent-server-01.
Register-NCacheEvaluation -Key xxxxxxxxx-xxxxxx-xxxxxxxx -FirstName your_first_name -LastName your_last_name -Email email@example.com -Company your_company_name
Step 5: Use NCache in Docker
Now that your container has been activated, you can use NCache as you want by executing the supported PowerShell commands and using the NCache Web Manager (explained in a later section). For example, the following command creates a cache named demoClusteredCache with two server nodes (172.19.0.11 and 172.19.0.12) with the topology set to PartitionedOfReplica, inside the container ncache-ent-server-01.
New-Cache -Name demoClusteredCache -Server "172.19.0.11,172.19.0.12" -Topology PartitionedofReplica -Size 1024
Using the NCache Web Manager
The NCache Web Manager is a very powerful tool that gives a GUI to manage and monitor your caches. Since we configured our NCache Docker containers to be accessible by the host, we can use the NCache Web Manager through the host’s web browser to manipulate our caches. To access the Web Manager of the container ncache-ent-server01, go to http://localhost:8251/ via your host machine’s web browser.
Connecting a Client Application
Once you have created your NCache containers, activated them, and created your clustered cache(s), you can proceed to connect your client applications to the clustered cache(s). Depending on where your client application is deployed (application can be containerized within the same network as the servers or the application can be present on the host machine, etc.), you may have to make some additional configurations.
Once you have connected your client application to the clustered cache(s), you can reap the benefits of the feature-rich NCache Client-Side API. NCache also provides Dockerfiles to create Docker Images for Windows and Linux. You can modify these DockerFiles as per your liking to create a custom NCache Docker Image and package your application within it.
The Docker Images of NCache save the users time by providing every dependency and configuration of NCache within them. Users no longer have to install each and everything required by NCache just to run it. If you want to use NCache with Docker, you are just a pull away from the vast API, tools, and features provided by NCache. So, what are you waiting for? Use NCache now!