docker file updated
parent
6a6792634e
commit
71d9f88ef3
@ -1,117 +1,106 @@
|
||||
# Docker Setup for Digital Twin Monitoring Application
|
||||
# Docker Setup for Digital Twin Monitoring
|
||||
|
||||
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
|
||||
This document provides instructions for setting up and running the Digital Twin Monitoring application using Docker.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Docker and Docker Compose installed on your production server
|
||||
- Access to PostgreSQL databases (configured in environment variables)
|
||||
|
||||
## Deployment Instructions
|
||||
- Ubuntu server
|
||||
- Internet connection
|
||||
- Basic knowledge of terminal commands
|
||||
|
||||
### Option 1: Using Docker Compose (Recommended)
|
||||
## Quick Start
|
||||
|
||||
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:
|
||||
The easiest way to get started is to run the provided installation script:
|
||||
|
||||
```bash
|
||||
cd Docker
|
||||
docker-compose up -d
|
||||
chmod +x install.sh
|
||||
./install.sh
|
||||
```
|
||||
|
||||
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
|
||||
This script will:
|
||||
1. Check if Docker is installed and install it if needed
|
||||
2. Build the Docker image
|
||||
3. Stop any existing containers with the same name
|
||||
4. Start a new container with the application
|
||||
|
||||
### Option 2: Using Docker Directly
|
||||
After running the script, the application will be available at `http://[server-ip]:5003`.
|
||||
|
||||
If you prefer to use Docker without Docker Compose:
|
||||
## Manual Setup
|
||||
|
||||
1. Copy the entire project to your production server
|
||||
2. Navigate to the project root directory
|
||||
3. Build the Docker image:
|
||||
If you prefer to set up manually, follow these steps:
|
||||
|
||||
### 1. Build the Docker image
|
||||
|
||||
```bash
|
||||
docker build -t digital-twin-monitoring -f Docker/Dockerfile .
|
||||
```
|
||||
|
||||
4. Run the container:
|
||||
### 2. Run the Docker 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 \
|
||||
--name digital-twin-monitoring \
|
||||
--restart unless-stopped \
|
||||
-p 5003:5003 \
|
||||
--env-file .env \
|
||||
digital-twin-monitoring
|
||||
```
|
||||
|
||||
Replace `your_token` and `your_chat_id` with your actual Telegram credentials.
|
||||
## Environment Variables
|
||||
|
||||
## Accessing the Application
|
||||
The application uses the following environment variables from the `.env` file:
|
||||
|
||||
Once deployed, the application will be available at:
|
||||
- `TELEGRAM_BOT_TOKEN`: Token for Telegram bot notifications
|
||||
- `TELEGRAM_CHAT_ID`: Chat ID for Telegram notifications
|
||||
- `DB_HOST_1`: PostgreSQL host for tables: pf_parts, ms_equipment_master
|
||||
- `DB_HOST_2`: PostgreSQL host for table: dl_pi_fetch_last
|
||||
- `DB_PORT`: PostgreSQL port
|
||||
- `DB_USER`: PostgreSQL username
|
||||
- `DB_PASS`: PostgreSQL password
|
||||
- `DB_NAME`: PostgreSQL database name
|
||||
|
||||
```
|
||||
http://your-server-ip:5003
|
||||
```
|
||||
Make sure your `.env` file is properly configured before running the container.
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Viewing Logs
|
||||
### Viewing logs
|
||||
|
||||
```bash
|
||||
# Using Docker Compose
|
||||
docker-compose logs -f
|
||||
docker logs digital-twin-monitoring
|
||||
```
|
||||
|
||||
### Stopping the container
|
||||
|
||||
# Using Docker directly
|
||||
docker logs -f digital-twin-app
|
||||
```bash
|
||||
docker stop digital-twin-monitoring
|
||||
```
|
||||
|
||||
### Stopping the Application
|
||||
### Restarting the container
|
||||
|
||||
```bash
|
||||
# Using Docker Compose
|
||||
docker-compose down
|
||||
docker restart digital-twin-monitoring
|
||||
```
|
||||
|
||||
### Removing the container
|
||||
|
||||
# Using Docker directly
|
||||
docker stop digital-twin-app
|
||||
docker rm digital-twin-app
|
||||
```bash
|
||||
docker stop digital-twin-monitoring
|
||||
docker rm digital-twin-monitoring
|
||||
```
|
||||
|
||||
### Updating the Application
|
||||
### Updating the application
|
||||
|
||||
1. Pull the latest code changes
|
||||
2. Rebuild and restart:
|
||||
To update the application, pull the latest code, rebuild the image, and restart the container:
|
||||
|
||||
```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
|
||||
git pull
|
||||
docker build -t digital-twin-monitoring -f Docker/Dockerfile .
|
||||
# Then run the container again with the same parameters as above
|
||||
docker stop digital-twin-monitoring
|
||||
docker rm digital-twin-monitoring
|
||||
docker run -d \
|
||||
--name digital-twin-monitoring \
|
||||
--restart unless-stopped \
|
||||
-p 5003:5003 \
|
||||
--env-file .env \
|
||||
digital-twin-monitoring
|
||||
```
|
||||
@ -1,27 +0,0 @@
|
||||
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
|
||||
@ -0,0 +1,46 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit on error
|
||||
set -e
|
||||
|
||||
echo "Starting Digital Twin Monitoring installation..."
|
||||
|
||||
# Check if Docker is installed
|
||||
if ! command -v docker &> /dev/null; then
|
||||
echo "Docker is not installed. Installing Docker..."
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y docker-ce
|
||||
sudo systemctl enable docker
|
||||
sudo systemctl start docker
|
||||
sudo usermod -aG docker $USER
|
||||
echo "Docker installed successfully. You may need to log out and log back in for group changes to take effect."
|
||||
else
|
||||
echo "Docker is already installed."
|
||||
fi
|
||||
|
||||
# Build the Docker image
|
||||
echo "Building Docker image..."
|
||||
sudo docker build -t digital-twin-monitoring -f Docker/Dockerfile .
|
||||
|
||||
# Check if container is already running and stop it
|
||||
if sudo docker ps -a | grep -q digital-twin-monitoring; then
|
||||
echo "Stopping existing container..."
|
||||
sudo docker stop digital-twin-monitoring || true
|
||||
sudo docker rm digital-twin-monitoring || true
|
||||
fi
|
||||
|
||||
# Run the Docker container
|
||||
echo "Starting Docker container..."
|
||||
sudo docker run -d \
|
||||
--name digital-twin-monitoring \
|
||||
--restart unless-stopped \
|
||||
-p 5003:5003 \
|
||||
--env-file .env \
|
||||
digital-twin-monitoring
|
||||
|
||||
echo "Installation completed successfully!"
|
||||
echo "Digital Twin Monitoring is now running at http://localhost:5003"
|
||||
Loading…
Reference in New Issue