In this docker, we use a node for the backend
771
This repository contains a Node.js application that connects to a Kafka cluster, consumes messages, and sends them to connected WebSocket clients. The application is containerized using Docker and can be deployed using Docker Compose.
The application uses the following environment variables which should be defined in a .env file:
KAFKA_BROKERS: List of Kafka brokers, separated by commasKAFKA_TOPIC: Kafka topic to subscribe toKAFKA_USERNAME: SASL username for Kafka authenticationKAFKA_PASSWORD: SASL password for Kafka authenticationKAFKA_PROTOCOL: Protocol for Kafka (e.g., SASL_SSL)KAFKA_MECHANISM: SASL mechanism (e.g., PLAIN)PORT: Port on which the WebSocket server will listenClone the repository:
git clone https://github.com/yourusername/node-app.git
cd node-app
Create a .env file and populate it with your environment variables:
KAFKA_BROKERS=
KAFKA_TOPIC=
KAFKA_USERNAME=
KAFKA_PASSWORD=
KAFKA_PROTOCOL=
KAFKA_MECHANISM=
PORT=
Build the Docker image:
docker-compose build
Run the Docker container:
docker-compose up
Build the Docker image:
docker build -t yourusername/node-app:latest .
Login to Docker Hub:
docker login
Push the Docker image to Docker Hub:
docker push yourusername/node-app:latest
Install dependencies:
npm install
Run the application:
npm start
To use Docker Compose for local development and testing, follow these steps:
Create a docker-compose.yml file in the root of your project:
version: '3.3'
services:
node-app:
build:
context: .
dockerfile: Dockerfile
args:
- PORT=${PORT}
container_name: mhp-node
ports:
- "${PORT}:${PORT}"
env_file:
- .env
volumes:
- ./:/usr/src/app
- ./cm-auto-in_cluster_ca_cert.pem:/usr/src/app/cm-auto-in_cluster_ca_cert.pem
- ./truststore.jks:/usr/src/app/truststore.jks
Run Docker Compose:
docker-compose up
Stop Docker Compose:
docker-compose down
This project is licensed under the MIT License.
Content type
Image
Digest
sha256:48f2e980e…
Size
421.2 MB
Last updated
almost 2 years ago
docker pull asobchenyuk/node-app