Step‑by‑Step Deployment of Frontend and Backend High‑Availability Services Using Docker, Nginx and Keepalived
This tutorial explains how to solve physical‑machine shortages and achieve high availability by installing Docker, configuring Keepalived for virtual IP failover, setting up Nginx load balancing, building backend Docker images, deploying master‑slave containers, and verifying the setup with Portainer.
The article addresses the problem of insufficient physical servers and demonstrates a complete solution for building a highly available front‑end and back‑end system using Docker, Keepalived, and Nginx.
System preparation : install Docker on an Ubuntu 16.04 host (minimum 4 CPU, 8 GB RAM) and create a custom Docker network mynet with a subnet (e.g., 172.18.0.0/24).
Keepalived installation : download the source, install required build tools, compile and install Keepalived, then create the service scripts ( /etc/keepalived/keepalived.conf) with a virtual IP (e.g., 172.18.0.220) and VRRP instance configuration. Adjust the startup script to use . /lib/lsb/init-functions for compatibility with non‑RedHat systems.
Nginx setup : install the official Nginx package, configure an upstream block pointing to backend servers, and set the virtual server to listen on the virtual IP. Add a simple HTML page with a Vue.js front‑end that calls /api/test on the backend.
Backend Docker image : create a Dockerfile based on openjdk:10 that copies docker_server.jar and runs it with java -jar. Build the image ( docker build -t myopenjdk .) and create six data volumes (S1‑S6) to store the JAR file.
Deploy backend containers : run six containers ( server_1 … server_6) on mynet with static IPs ( 172.18.0.101 ‑ .106) and mount the corresponding data volume. Each container starts the Java application automatically.
High‑availability front‑end containers : create two Keepalived‑enabled containers ( centos_web_master and centos_web_slave) with different priorities and VRRP states (MASTER/SLAVE). Configure Nginx inside each container to proxy to the backend pool and to use the same virtual IP ( 172.18.0.210).
Testing : access the virtual IP from a browser; the page shows the Vue.js UI and displays the backend server port returned by /api/test. Stop the master container to verify automatic failover to the slave, and stop individual backend containers to confirm Nginx load‑balancing.
Portainer installation : pull the Portainer image and run it with -p 9000:9000 and -v /var/run/docker.sock:/var/run/docker.sock. Use the web UI (admin/password) to monitor all containers and their statuses.
The guide concludes with a reminder that deeper topics such as Docker Compose, Kubernetes, and advanced network management require further study.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
