docs: add DOCKER_GUIDE.md and fix .env parsing; chore: update docker and script configurations
This commit is contained in:
89
DOCKER_GUIDE.md
Normal file
89
DOCKER_GUIDE.md
Normal file
@ -0,0 +1,89 @@
|
||||
# Docker Management & Troubleshooting Guide
|
||||
|
||||
This guide provides the necessary commands to build, manage, and troubleshoot the BTC Bot Docker environment.
|
||||
|
||||
## 1. Manual Build Commands
|
||||
Always execute these commands from the **project root** directory.
|
||||
|
||||
```bash
|
||||
# Build the Data Collector
|
||||
docker build --network host -f docker/Dockerfile.collector -t btc_collector .
|
||||
|
||||
# Build the API Server
|
||||
docker build --network host -f docker/Dockerfile.api -t btc_api .
|
||||
|
||||
# Build the Bot (Ensure the tag matches docker-compose.yml)
|
||||
docker build --no-cache --network host -f docker/Dockerfile.bot -t btc_ping_pong_bot .
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. Managing Containers
|
||||
Run these commands from the **docker/** directory (`~/btc_bot/docker`).
|
||||
|
||||
### Restart All Services
|
||||
```bash
|
||||
# Full reset: Stop, remove, and recreate all containers
|
||||
docker-compose down
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### Partial Restart (Specific Service)
|
||||
```bash
|
||||
# Rebuild and restart only the bot (ignores dependencies like DB)
|
||||
docker-compose up -d --no-deps ping_pong_bot
|
||||
```
|
||||
|
||||
### Stop/Start Services
|
||||
```bash
|
||||
docker-compose stop <service_name> # Temporarily stop
|
||||
docker-compose start <service_name> # Start a stopped container
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Checking Logs
|
||||
Use these commands to diagnose why a service might be crashing or restarting.
|
||||
|
||||
```bash
|
||||
# Follow live logs for the Bot (last 100 lines)
|
||||
docker-compose logs -f --tail 100 ping_pong_bot
|
||||
|
||||
# Follow live logs for the Collector
|
||||
docker-compose logs -f btc_collector
|
||||
|
||||
# Follow live logs for the API Server
|
||||
docker-compose logs -f api_server
|
||||
|
||||
# View logs for ALL services combined
|
||||
docker-compose logs -f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Troubleshooting Checklist
|
||||
|
||||
| Symptom | Common Cause & Solution |
|
||||
| :--- | :--- |
|
||||
| **`.env` Parsing Warning** | Check for `//` comments (use `#` instead) or hidden characters at the start of the file. |
|
||||
| **Container "Restarting" Loop** | Check logs! Usually missing `API_KEY`/`API_SECRET` or DB connection failure. |
|
||||
| **"No containers to restart"** | Use `docker-compose up -d` first. `restart` only works for existing containers. |
|
||||
| **Database Connection Refused** | Ensure `DB_PORT=5433` is used for `host` network mode. Check if port is open with `netstat`. |
|
||||
| **Code Changes Not Applying** | Rebuild the image (`--no-cache`) if you changed `requirements.txt` or the `Dockerfile`. |
|
||||
|
||||
---
|
||||
|
||||
## 5. Useful Debugging Commands
|
||||
```bash
|
||||
# Check status of all containers
|
||||
docker-compose ps
|
||||
|
||||
# List all local docker images
|
||||
docker images
|
||||
|
||||
# Check if the database port is listening on the host
|
||||
netstat -tulnp | grep 5433
|
||||
|
||||
# Access the shell inside a running container
|
||||
docker exec -it btc_ping_pong_bot /bin/bash
|
||||
```
|
||||
Reference in New Issue
Block a user