NCache Docker Deployment Scenarios
NCache provides Enterprise and Professional Docker Images for Windows and Linux. Using these images, you can create and run your containers that act as NCache servers. Client applications can be connected to these containers under various conditions or scenarios. Each scenario may require a different configuration and setup on your end, depending on the operating system of your containers and host. These scenarios are discussed below:
- Client App and Servers are Containerized on the Same Machine.
- Client App is on Host and Servers are Containerized on the Same Machine.
- Client App and Servers are Containerized on Different Machines.
- Client App is on Different Machine and Servers are Containerized on Same Machine.
1. Client App and Servers are Containerized on the Same Machine
In this scenario, your client application and servers are present inside Docker containers, and all of these containers are running on the same machine. The operating system of your containers and your host may vary or be the same, but you won't have to make any extra configurations in this case.
2. Client App is on Host and Servers are Containerized on the Same Machine
In this scenario, your client application is present on the host, and servers are containerized on the same machine. Here you might have to make some configurations when the operating system of your containers and your host varies. The following are container-host operating system scenarios where you might have to make some changes to connect your servers with your client application:
Windows Containers on a Windows Host
In this scenario, your containers and host are windows based. You will not have to make any extra changes to your configuration or setup to connect your client application with your servers.
Linux Containers on a Windows Host
In this scenario, your containers are Linux-based and the host is Windows. When Linux-based containers are hosted on a non-Linux host (Windows/macOS), Docker doesn't expose its internal network to the host network. Hence, to make your containerized app accessible on the host machine or host network, you have to expose the container's ports to the host through -p switch of Docker create/run command. To cater to this scenario, NCache provides the Port Forwarding feature discussed in the later paragraphs. Using this, client apps will be able to connect with cache servers.
Linux Containers on a Linux Host
In this scenario, your containers and host are Linux based. You will not have to make any extra changes to your configuration or setup to connect your client application with your servers.
Linux Containers on a macOS Host
In this scenario, your containers are Linux-based and the host is macOS. The rest of the process is the same as linux-containers-on-a-windows-host, where the Docker itself does not expose its internal network to the host network, necessitating the use of the -p switch in Docker's create/run command to expose the container's ports to the host. NCache addresses this requirement by offering port forwarding functionality.
3. Client App and Servers are Containerized on Different Machines
In this scenario, your client application and your servers are containerized on different machines. Your containers will not be able to communicate with each other directly in this scenario. So, to ensure their communication with each other, use Kubernetes or Docker Swarm for all container-host operating system scenarios.
4. Client App is on Different Machine and Servers are Containerized on Same Machine
In this scenario, your client application is either containerized or present on the host on a different machine, and your servers are containerized on the same machine. If the client application is present on the host on a different machine, Docker internal network ports will not be exposed to the host machine. So, make use of Port Forwarding for all container-host operating system scenarios.
If the client application is containerized on a different machine, refer to Client App and Servers are Containerized on Different Machines.
Port Forwarding for NCache in Docker
Port forwarding or port mapping redirects a communication request from one IP address and port number combination to another. Port forwarding exposes services to applications outside the host's internal network.
Here, port forwarding allows remote client applications to connect to the NCache servers running inside Docker containers (internal Docker network).
Configuration
There are some scenarios where you cannot access the NCache servers running inside Docker containers directly. You'll have to map NCache ports from the containers to the host machine network for accessibility. Additionally, you'll have to configure these ports for the client application. The configuration for both is explained below:
Configure Port Forwarding in Containers
Before you proceed with port forwarding, you need to assign NCache containers static IP addresses. NCache servers need to have static IP addresses to communicate with each other and with NCache clients. Also, NCache servers are not accessible to the NCache clients if both don't exist on the same network or subnet.
Step 1: Create a Custom Docker Network
By default, Docker assigns containers with dynamic IP addresses. Therefore, if the containers have to restart or the host machine restarts, the IP addresses of the containers might change. To assign containers static IP addresses, a custom Docker network is required.
The following command creates a custom Docker network named nbrg with a subnet and gateway defined:
docker network create --subnet=10.2.0.4/16 --gateway=10.2.0.1 nbrg
Step 2: Create NCache Containers and Map NCache Ports
Once the custom Docker network creation occurs, you may assign NCache containers static IP addresses and map NCache ports from the containers to the host for accessibility.
The following commands create two NCache Docker containers named ncache-server-01 and ncache-server-02. Two containers are assigned static IP addresses using the custom Docker network nbrg created in the last step. The NCache communication ports map from the containers to the host using the Docker -p switch:
For Enterprise, use the following commands:
docker run --name ncache-server-01 --net nbrg --ip 10.2.0.4 -p 1250-1260:8250-8260 -p 1300-1400:8300-8400 -p 9801:9800 -itd alachisoft/ncache:latest
docker run --name ncache-server-02 --net nbrg --ip=10.2.0.5 -p 2250-2260:8250-8260 -p 2300-2400:8300-8400 -p 9802:9800 -itd alachisoft/ncache:latest
Configure Port Forwarding for Client Application
Once you have mapped the ports from the containers to the host, you need to reflect that change for the client application, as well. The client.ncconf file uses the client application to establish a connection with the NCache servers. You need to map the ports and the IP addresses in this file.
The following is a client.ncconf file configuration where the ports map with the containers (NCache servers) ncache-server-01 and ncache-server-02, which were created previously and are hosted on the public IP address 20.200.20.212
:
<configuration>
<ncache-server connection-retries="1" retry-connection-delay="0" retry-interval="1" command-retries="3" command-retry-interval="0.1" client-request-timeout="90" connection-timeout="5" port="9800"/>
<cache id="demoCache" client-cache-id="" client-cache-syncmode="optimistic" skip-client-cache-if-unavailable="True" reconnect-client-cache-interval="10" default-readthru-provider="" default-writethru-provider="" load-balance="True" enable-client-logs="False" log-level="error">
<server name="10.2.0.4"/>
<server name="10.2.0.5"/>
</cache>
<server-end-point>
<end-point public-ip="20.200.20.212" public-ports="9801" private-ip="10.2.0.4" private-ports="9800"/>
<end-point public-ip="20.200.20.212" public-ports="1250-1260" private-ip="10.2.0.4" private-ports="8250-8260"/>
<end-point public-ip="20.200.20.212" public-ports="1300-1400" private-ip="10.2.0.4" private-ports="8300-8400"/>
<end-point public-ip="20.200.20.212" public-ports="9802" private-ip="10.2.0.5" private-ports="9800"/>
<end-point public-ip="20.200.20.212" public-ports="2250-2260" private-ip="10.2.0.5" private-ports="8250-8260"/>
<end-point public-ip="20.200.20.212" public-ports="2300-2400" private-ip="10.2.0.5" private-ports="8300-8400"/>
</server-end-point>
</configuration>
See Also
Create NCache Containers
NCache Docker on Windows
NCache Docker on Linux