• Facebook
  • Twitter
  • Youtube
  • LinedIn
  • RSS
  • Docs
  • Comparisons
  • Blogs
  • Download
  • Contact Us
Download
Show / Hide Table of Contents

Compose for Multiple Docker Instances (Eval)

Docker Compose is a command-line tool used to define, manage, and run multi-container applications using a YAML configuration file. The primary file used, compose.yaml, lets you describe your services, networks, volumes, and container behavior.

Note

Please note that Docker Compose is recommended for evaluation use only.

You can deploy a complete NCache cluster using Docker Compose by describing multiple NCache containers in the YAML file and running them together. For details on how Docker Compose works and its application model, refer to the official Docker guide. It offers multiple ways to configure container behavior, including support for lifecycle hooks such as post_start to run custom commands after a container starts, as discussed below.

Example: Compose File

Below is a sample compose.yaml file defining three NCache containers, each using the post_start lifecycle hook to register itself after startup.

Exposing Ports for Multiple NCache Instances

In a typical NCache deployment, each virtual machine or container hosts a single NCache instance, which exposes its required ports (such as client communication, management UI, and API) directly to the environment without conflict.

In contrast, within a Docker Compose environment, each NCache instance runs in its own container with a unique internal IP on the Docker network. However, from outside the Docker environment, all containers share the host's single public IP. This can lead to port conflicts since all instances use the same default ports internally.

To resolve this and allow external applications to connect to each NCache instance individually, you must map each container’s internal ports to unique host ports. This avoids port conflicts and ensures the incoming traffic is correctly routed to an appropriate container.

For a detailed explanation of the attributes used in this file, please refer to the Compose File Configuration Table.

# NCache Cluster Definition
name: myproject

services:
 ncache1:
    image: alachisoft/ncache:latest
    container_name: ncache1
    hostname: ncache1
    ports:
      - "8251:8251"             # Managment UI (http)
      - "9801:9800"             # Client Connection
      - "1800-1810:8300-8310"   # Cache Host Ports
    networks:
      ncache-net:
        ipv4_address: 172.28.0.11
    post_start:
      - command: "/opt/ncache/bin/tools/register-ncacheevaluation -firstname John -lastname Smith -email john@yourdomain.com -company your_company_name -key'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' "

  ncache2:
    image: alachisoft/ncache:latest
    container_name: ncache2
    hostname: ncache2
    ports:
      - "8252:8251"             # Managment UI (http)
      - "9802:9800"             # Client Connection
      - "2800-2810:8300-8310"   # Cache Host Ports
    networks:
      ncache-net:
        ipv4_address: 172.28.0.12
    post_start:
      - command: "/opt/ncache/bin/tools/register-ncacheevaluation -firstname John -lastname Smith -email john@yourdomain.com -company your_company_name -key'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' "

  ncache3:
    image: alachisoft/ncache:latest
    container_name: ncache3
    hostname: ncache3
    ports:
      - "8253:8251"             # Managment UI (http)
      - "9803:9800"             # Client Connection
      - "3800-3810:8300-8310"   # Cache Host Ports
    networks:
      ncache-net:
        ipv4_address: 172.28.0.13
    depends_on:
      - ncache1
      - ncache2
    post_start:
      - command: "/opt/ncache/bin/tools/register-ncacheevaluation -firstname John -lastname Smith -email john@yourdomain.com -company your_company_name -key'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' "

networks:
  ncache-net:
    driver: bridge
    ipam:
      config:
        - subnet: 172.28.0.0/24

Docker Compose Commands

Next, use the following command to start all services defined in your compose.yaml file:

docker compose up

Furthermore, use the following command to stop the running NCache containers using docker compose:

docker compose down

This command stops and removes all containers, networks, and volumes created by docker compose up.

You can also view logs with:

docker compose logs

For further details, please refer to the official Docker guide.

The following section explains the post_start lifecycle hook registration method, demonstrated in the above compose.yaml file.

Using post_start Lifecycle Hook

You can use the post_start hook in Docker Compose to run a command after the container starts. The post_start lifecycle hook allows you to define custom commands, which is useful for running setup operations, such as activating NCache containers using the registration tool right after the container is up. This method gives you flexibility and works consistently across all NCache versions. For more details, see the official Docker guide on post_start hooks.

Important

The post_start lifecycle hook is supported in Docker Compose version 2.30.0 and above. Ensure you are using this version or later to use post_start commands in your Compose files.

Compose File Attributes

The following table explains the key attributes used in the above compose.yaml file for setting up a multi-container NCache cluster using Docker Compose.

Attribute Description
services Top-level block defining all NCache container instances.
image Docker image to use for the container (for e.g. alachisoft/ncache:latest).
container_name Explicit name assigned to each container instance.
hostname Internal hostname used by NCache for cluster discovery.
ports Maps container ports to host ports for management, client access, and internal communication. Following are the ports specified in the compose.yaml file:

- 8251:8251 for management UI.
- 9801:9800 for client connection.
- 1800–1810:8300–8310 for internal cache host communication.
depends_on Ensures containers start in the correct order (for e.g. ncache3 waits for ncache1 and ncache2).
post_start Lifecycle hook used to execute commands (for e.g. register NCache) after the container starts.
networks (under service) Connects containers to a user-defined bridge network (for e.g. ncache-net).
networks (root level) Declares the actual ncache-net network and configures subnet/IP range.
driver: bridge Specifies Docker’s bridge networking driver that allows cross-container communication.
ipam → config → subnet Defines a custom subnet to assign static IPs (for e.g. 172.28.0.0/24).

See Also

Upgrade NCache Versions
Licensing Model
Evaluation Period Management

Contact Us

PHONE

+1 (214) 764-6933   (US)

+44 20 7993 8327   (UK)

 
EMAIL

sales@alachisoft.com

support@alachisoft.com

NCache
  • NCache Enterprise
  • NCache Community
  • Edition Comparison
  • NCache Architecture
  • Benchmarks
Download
Pricing
Try Playground

Deployments
  • Cloud (SaaS & Software)
  • On-Premises
  • Kubernetes
  • Docker
Technical Use Cases
  • ASP.NET Sessions
  • ASP.NET Core Sessions
  • Pub/Sub Messaging
  • Real-Time ASP.NET SignalR
  • Internet of Things (IoT)
  • NoSQL Database
  • Stream Processing
  • Microservices
Resources
  • Magazine Articles
  • Third-Party Articles
  • Articles
  • Videos
  • Whitepapers
  • Shows
  • Talks
  • Blogs
  • Docs
Customer Case Studies
  • Testimonials
  • Customers
Support
  • Schedule a Demo
  • Forum (Google Groups)
  • Tips
Company
  • Leadership
  • Partners
  • News
  • Events
  • Careers
Contact Us

  • EnglishChinese (Simplified)FrenchGermanItalianJapaneseKoreanPortugueseSpanish

  • Contact Us
  •  
  • Sitemap
  •  
  • Terms of Use
  •  
  • Privacy Policy
© Copyright Alachisoft 2002 - . All rights reserved. NCache is a registered trademark of Diyatech Corp.
Back to top