docker file

main
ariwahyunahar 5 months ago
parent d00653828a
commit 792893a56e

@ -0,0 +1,18 @@
FROM python:3.10-slim
WORKDIR /app
# Copy requirements first for better caching
COPY requirements.txt .
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application
COPY . .
# Expose the port the app runs on
EXPOSE 5003
# Command to run the application
CMD ["python", "app.py"]

@ -0,0 +1,117 @@
# Docker Setup for Digital Twin Monitoring Application
This folder contains Docker configuration files for deploying the Digital Twin Monitoring application in a production environment.
## Files
- `Dockerfile`: Defines how to build the application container
- `docker-compose.yml`: Defines the services and their configurations
## Prerequisites
- Docker and Docker Compose installed on your production server
- Access to PostgreSQL databases (configured in environment variables)
## Deployment Instructions
### Option 1: Using Docker Compose (Recommended)
1. Copy the entire project to your production server
2. Navigate to the project root directory
3. Make sure your `.env` file is properly configured with:
- `TELEGRAM_BOT_TOKEN`
- `TELEGRAM_CHAT_ID`
- Database connection details (optional, defaults are provided)
4. Run the following command:
```bash
cd Docker
docker-compose up -d
```
This will:
- Build the Docker image using the Dockerfile
- Start the container in detached mode
- Map port 5003 to the host
- Configure environment variables
- Set up restart policies
### Option 2: Using Docker Directly
If you prefer to use Docker without Docker Compose:
1. Copy the entire project to your production server
2. Navigate to the project root directory
3. Build the Docker image:
```bash
docker build -t digital-twin-monitoring -f Docker/Dockerfile .
```
4. Run the container:
```bash
docker run -d \
--name digital-twin-app \
-p 5003:5003 \
-e DB_HOST_1=192.168.1.85 \
-e DB_HOST_2=192.168.1.86 \
-e DB_PORT=5432 \
-e DB_USER=postgres \
-e DB_PASS=postgres \
-e DB_NAME=digital_twin \
-e TELEGRAM_BOT_TOKEN=your_token \
-e TELEGRAM_CHAT_ID=your_chat_id \
--restart unless-stopped \
digital-twin-monitoring
```
Replace `your_token` and `your_chat_id` with your actual Telegram credentials.
## Accessing the Application
Once deployed, the application will be available at:
```
http://your-server-ip:5003
```
## Maintenance
### Viewing Logs
```bash
# Using Docker Compose
docker-compose logs -f
# Using Docker directly
docker logs -f digital-twin-app
```
### Stopping the Application
```bash
# Using Docker Compose
docker-compose down
# Using Docker directly
docker stop digital-twin-app
docker rm digital-twin-app
```
### Updating the Application
1. Pull the latest code changes
2. Rebuild and restart:
```bash
# Using Docker Compose
docker-compose down
docker-compose up -d --build
# Using Docker directly
docker stop digital-twin-app
docker rm digital-twin-app
docker build -t digital-twin-monitoring -f Docker/Dockerfile .
# Then run the container again with the same parameters as above
```

@ -0,0 +1,27 @@
version: '3'
services:
app:
build:
context: ..
dockerfile: Docker/Dockerfile
ports:
- "5003:5003"
environment:
- DB_HOST_1=${DB_HOST_1:-192.168.1.85}
- DB_HOST_2=${DB_HOST_2:-192.168.1.86}
- DB_PORT=${DB_PORT:-5432}
- DB_USER=${DB_USER:-postgres}
- DB_PASS=${DB_PASS:-postgres}
- DB_NAME=${DB_NAME:-digital_twin}
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
- TELEGRAM_CHAT_ID=${TELEGRAM_CHAT_ID}
volumes:
- ../.env:/app/.env
restart: unless-stopped
networks:
- app-network
networks:
app-network:
driver: bridge

@ -1,12 +0,0 @@
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["python", "app.py"]

@ -431,4 +431,4 @@ def get_part_history():
return jsonify(result) return jsonify(result)
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True) app.run(host='0.0.0.0', port=5003, debug=True)

@ -140,7 +140,7 @@ function updateTable(data) {
tableResponsive.className = 'table-responsive'; tableResponsive.className = 'table-responsive';
const table = document.createElement('table'); const table = document.createElement('table');
table.className = 'table table-striped table-hover'; table.className = 'table table-hover';
const tableHeader = document.createElement('thead'); const tableHeader = document.createElement('thead');
tableHeader.innerHTML = ` tableHeader.innerHTML = `

Loading…
Cancel
Save