More attempts to fix docker

This commit is contained in:
2025-04-21 23:22:32 +02:00
parent 063877bc09
commit 2e265c08f1
17 changed files with 1567 additions and 116 deletions

View File

@@ -2,6 +2,10 @@
This guide explains how to use Docker to build and run the Svelte MUD client.
## Solution Overview
This setup runs both the SvelteKit application and the WebSocket server in a single container, avoiding CORS issues. It follows the same approach used in development, where both servers run as separate processes but within the same context.
## Prerequisites
- [Docker](https://docs.docker.com/get-docker/)
@@ -14,14 +18,14 @@ This guide explains how to use Docker to build and run the Svelte MUD client.
cd path/to/svelte-mud
```
2. Build and start the containers:
2. Build and start the container:
```bash
docker-compose up -d
```
3. Access the application:
- Web interface: http://localhost:3000
- WebSocket server: ws://localhost:3000/mud-ws (both services now run on the same port)
- WebSocket server: ws://localhost:3001/mud-ws
## Docker Commands
@@ -43,57 +47,31 @@ docker-compose up --build
```bash
# Stop containers
docker-compose down
# Stop containers and remove volumes
docker-compose down -v
```
### Viewing Logs
```bash
# View all logs
docker-compose logs
# Follow logs
# View logs
docker-compose logs -f
# View logs for specific service
docker-compose logs -f svelte-mud
```
## Configuration
## Caddy Configuration
The Docker setup uses a single port for both the web interface and WebSocket server:
- Port 3000: Unified server (Web + WebSocket)
For use with Caddy as a reverse proxy, use this simple configuration:
You can modify these ports in the `docker-compose.yml` file if needed.
## Customization
### Environment Variables
You can add environment variables in the `docker-compose.yml` file:
```yaml
services:
svelte-mud:
environment:
- NODE_ENV=production
- PORT=3000
# Add your custom environment variables here
```
mud.example.com {
reverse_proxy svelte-mud:3000
}
```
### Building for Production
The default configuration is optimized for production use. It:
- Uses a multi-stage build process to minimize image size
- Runs as a non-root user for better security
- Includes only production dependencies
Both the web interface and WebSocket connections will be routed correctly through this single reverse proxy rule.
## Troubleshooting
1. **Port conflicts**: If port 3000 is already in use, modify the port mapping in `docker-compose.yml`.
If you encounter any issues, check the container logs:
2. **Build failures**: Ensure that all dependencies are properly defined in your package.json.
3. **Connection issues**: If you can't connect to the WebSocket server, verify that your client is using the correct URL format: `ws://localhost:3000/mud-ws?host=YOUR_MUD_HOST&port=YOUR_MUD_PORT`.
```bash
docker-compose logs -f
```