Skip to content

add managing multiple docker containers with the same image files #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:24-alpine

WORKDIR /app

COPY app/ ./app/
WORKDIR /app/app

RUN npm init -y && npm install express

EXPOSE 3000

CMD ["node", "index.js"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const express = require("express");
const fs = require("fs");
const path = require("path");

const app = express();

let config = {
SERVICE_NAME: process.env.SERVICE_NAME || "default-service",
ENVIRONMENT: process.env.ENVIRONMENT || "development",
LOG_LEVEL: process.env.LOG_LEVEL || "info",
PORT: process.env.PORT || 3000,
};

if (process.env.CONFIG_PATH) {
try {
const configPath = path.resolve(process.env.CONFIG_PATH);
const fileContent = fs.readFileSync(configPath, "utf-8");
const fileConfig = JSON.parse(fileContent);
config = { ...config, ...fileConfig };
console.log(`[INFO] Loaded config from ${configPath}`);
} catch (err) {
console.error(
`[ERROR] Failed to load config from ${process.env.CONFIG_PATH}:`,
err.message
);
}
}

console.log(
`[INFO] Starting ${config.SERVICE_NAME} in ${config.ENVIRONMENT} mode (log level: ${config.LOG_LEVEL})`
);

app.get("/", (req, res) => {
res.send(`
<h1>Service: ${config.SERVICE_NAME}</h1>
<p>Environment: ${config.ENVIRONMENT}</p>
<p>Log level: ${config.LOG_LEVEL}</p>
<p>Running on port ${config.PORT}</p>
`);
});

app.listen(config.PORT, () => {
console.log(`✅ ${config.SERVICE_NAME} is running on port ${config.PORT}`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"SERVICE_NAME": "analytics-processor",
"ENVIRONMENT": "staging",
"LOG_LEVEL": "debug",
"PORT": 3005
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"SERVICE_NAME": "notification-worker",
"ENVIRONMENT": "production",
"LOG_LEVEL": "info",
"PORT": 3006
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
audit_logger:
build:
context: .
dockerfile: Dockerfile
container_name: audit_logger
environment:
- SERVICE_NAME=audit-logger
- ENVIRONMENT=qa
- LOG_LEVEL=warn
- PORT=3003
ports:
- "3003:3003"

report_engine:
build:
context: .
dockerfile: Dockerfile
container_name: report_engine
environment:
- SERVICE_NAME=report-engine
- ENVIRONMENT=dev
- LOG_LEVEL=error
- PORT=3004
ports:
- "3004:3004"
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
analytics_processor:
build:
context: .
dockerfile: Dockerfile
container_name: analytics_processor
environment:
- CONFIG_PATH=/app/config.json
volumes:
- ./config/analytics-config.json:/app/config.json
ports:
- "3005:3005"

notification_worker:
build:
context: .
dockerfile: Dockerfile
container_name: notification_worker
environment:
- CONFIG_PATH=/app/config.json
volumes:
- ./config/notification-config.json:/app/config.json
ports:
- "3006:3006"