Using NCache Images
NCache provides Docker images for the following editions and components located at Alachisoft NCache’s repository on Docker Hub:
- NCache 4.8 Enterprise Server
- NCache 4.8 Enterprise Client
- NCache 4.8 Community Server
- NCache 4.8 Community Client
Pull Image from Source
Once the Docker environment has been set, pull the NCache hosted images from Docker Hub.
The following command pulls the ncache:server-enterprise-4.8
image and uses it
throughout the chapter.
docker pull alachisoft/ncache:enterprise-server-4.8
NCache 4.8 Enterprise Server can also be downloaded from the following commands:
docker pull alachisoft/ncache
docker pull alachisoft/ncache:latest
Configure Transparent Network
Transparent network uses IPs from host network and each container is assigned a separate virtual NIC. This network best suits network configuration needed for NCache. Each container acts as a separate node and can communicate across hosts on the same network, meaning that the NCache cluster can be managed anywhere from that network. Containers attached to a network created with the transparent driver will be directly connected to the physical network. IPs from physical network can be assigned statically or dynamically.
Important
It is highly recommended to use static IPs for each container as all future connections will take place using this IP. These IPs should exist in the IP range specified in the transparent network created.
Following script creates a transparent network called transNet which contains subnet 20.200.20.0/24 and specifies the gateway as 20.200.20.1.
docker network create -d transparent --subnet=20.200.20.0/24 --gateway=20.200.20.1 transNet
Create Container from Image
Once the image is pulled, you can create containers which host NCache and use it. You can limit the container’s resources at this point, as Windows container does not support altering container’s CPU or memory once it is created. Moreover, you can assign different network interfaces to the container and mount shared volumes between containers and host.
The container can be created with either docker
run or docker
create command,
the difference being docker run
starts the container when it is created.
Important
It is highly recommended to use static IPs for each container as all future connections will take place using this IP. These IPs should exist in the IP range specified in the transparent network created.
Note that while creating containers, the image specified should exist locally. If not, the image is then fetched from Docker Hub if the name of the repository is specified.
The following commands create the containers named ncache-server-01
and
ncache-server-02
in the shipped image
(alachisoft/ncache:server-enterprise-4.8) in detached mode using the configured
transparent network:
docker run -d --name=ncache-ent-server-01 --net=transNet --ip=20.200.20.251 alachisoft/ncache:server-enterprise-4.8
docker run -d --name=ncache—ent-server-02 --net=transNet --ip=20.200.20.252 alachisoft/ncache:server-enterprise-4.8
Connect to Container
You can now access these containers remotely, by using
Enter-PSSession
command and specifying the container name of the newly created container. The
get-container
command returns the container ID which is used as a value for
the ContainerId
parameter.
Enter-PSSession -ContainerId (get-container -Name ncache-ent-server-01).ID –RunAsAdministrator
You will be directed to the container instance and can seamlessly perform NCache tasks through this container.
Use NCache in Docker (Examples)
Once connected to the container, you can perform administrative tasks through NCache PowerShell commands. This includes managing caches, clusters, security and deploying providers and much more.
For starters, you can verify NCache installation through Get-NCacheVersion
cmdlet. This lists the NCache version detail along with licensing information.
You can proceed to using NCache within Docker now.
For example, the following commands perform the following tasks:
- Displays status of the NCache service.
- Create a new partitioned cache and add a new node to it.
- Start the cache and add test data of 50 items to it.
- Verify the cache count.
Get-Service -Name "NCacheSvc"
New-Cache -CacheName democache -Topology Partitioned -Server 20.200.20.251 -Size 1024
Add-Node -CacheName demoCache -ExistingServer 20.200.20.251 -NewServer 20.200.20.252
Start-Cache -CacheName democache
Add-TestData -CacheName democache –ItemCount 50
Get-CacheCount -CacheName democache