> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/sammwyy/mikuMikuBeam/llms.txt
> Use this file to discover all available pages before exploring further.

# Docker Deployment

> Deploy Miku Miku Beam using Docker for containerized environments

## Overview

While Miku Miku Beam doesn't include a pre-built Dockerfile in the repository, it's designed to be Docker-ready and can be easily containerized for deployment. This guide will walk you through creating and deploying MMB in a Docker container.

## Creating a Dockerfile

### Multi-stage Dockerfile

Create a `Dockerfile` in the project root with the following content:

```dockerfile theme={null}
# Build stage for web client
FROM node:18-alpine AS web-builder
WORKDIR /app/web-client
COPY web-client/package*.json ./
RUN npm install --no-audit --no-fund
COPY web-client/ ./
RUN npm run build

# Build stage for Go binaries
FROM golang:1.21-alpine AS go-builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN mkdir -p bin/web-client
COPY --from=web-builder /app/web-client/dist/public/* bin/web-client/
RUN go build -o bin/mmb-server ./cmd/mmb-server
RUN go build -o bin/mmb-cli ./cmd/mmb-cli

# Final runtime stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /app

# Copy binaries and web assets
COPY --from=go-builder /app/bin/mmb-server /app/mmb-server
COPY --from=go-builder /app/bin/mmb-cli /app/mmb-cli
COPY --from=go-builder /app/bin/web-client /app/bin/web-client

# Create data directory for configuration
RUN mkdir -p /app/data

# Expose the server port
EXPOSE 3000

# Run the server
CMD ["/app/mmb-server"]
```

## Docker Compose Setup

Create a `docker-compose.yml` file for easier deployment:

```yaml theme={null}
version: '3.8'

services:
  mmb-server:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: miku-miku-beam
    ports:
      - "3000:3000"
    volumes:
      - ./data:/app/data
      - ./config.toml:/app/config.toml:ro
    environment:
      - LOG_FORMAT=json
      - ALLOW_NO_PROXY=false
    restart: unless-stopped
    networks:
      - mmb-network

networks:
  mmb-network:
    driver: bridge
```

## Building the Image

<Steps>
  <Step title="Build with Docker">
    Build the Docker image directly:

    ```bash theme={null}
    docker build -t miku-miku-beam:latest .
    ```
  </Step>

  <Step title="Or build with Docker Compose">
    Build using Docker Compose:

    ```bash theme={null}
    docker-compose build
    ```
  </Step>
</Steps>

## Configuration Files

Before running the container, prepare the required configuration files:

<Steps>
  <Step title="Create data directory">
    ```bash theme={null}
    mkdir -p data
    ```
  </Step>

  <Step title="Create proxies.txt">
    Add your proxy list (one per line):

    ```bash theme={null}
    cat > data/proxies.txt <<EOF
    http://proxy1.example.com:8080
    http://user:pass@proxy2.example.com:3128
    socks5://proxy3.example.com:1080
    EOF
    ```

    <Warning>
      Proxy format supports:

      * `protocol://user:password@host:port` (with authentication)
      * `protocol://host:port`
      * `host:port` (defaults to HTTP)
      * `host` (defaults to port 8080)
    </Warning>
  </Step>

  <Step title="Create uas.txt">
    Add user agent strings (one per line):

    ```bash theme={null}
    cat > data/uas.txt <<EOF
    Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
    Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36
    Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36
    EOF
    ```
  </Step>

  <Step title="Create config.toml (optional)">
    Override default configuration:

    ```toml theme={null}
    proxies_file = "data/proxies.txt"
    user_agents_file = "data/uas.txt"
    server_port = 3000
    allowed_origin = "http://localhost:5173"
    ```
  </Step>
</Steps>

## Running the Container

### Using Docker Run

```bash theme={null}
docker run -d \
  --name miku-miku-beam \
  -p 3000:3000 \
  -v $(pwd)/data:/app/data \
  -e LOG_FORMAT=json \
  -e ALLOW_NO_PROXY=false \
  --restart unless-stopped \
  miku-miku-beam:latest
```

### Using Docker Compose

```bash theme={null}
# Start the service
docker-compose up -d

# View logs
docker-compose logs -f

# Stop the service
docker-compose down
```

## Environment Variables

<ParamField path="LOG_FORMAT" type="string" default="console">
  Log output format. Set to `json` for structured logging in production
</ParamField>

<ParamField path="ALLOW_NO_PROXY" type="boolean" default="false">
  Allow running attacks without proxies. Set to `true` to enable
</ParamField>

## Volume Mounts

| Host Path       | Container Path     | Purpose                         |
| --------------- | ------------------ | ------------------------------- |
| `./data`        | `/app/data`        | Proxies and user agents storage |
| `./config.toml` | `/app/config.toml` | Configuration file (optional)   |

## Port Mappings

| Container Port | Protocol | Purpose        |
| -------------- | -------- | -------------- |
| 3000           | HTTP     | Web UI and API |

## Health Checks

Add a health check to your Dockerfile:

```dockerfile theme={null}
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD wget --no-verbose --tries=1 --spider http://localhost:3000/attacks || exit 1
```

Or in docker-compose.yml:

```yaml theme={null}
services:
  mmb-server:
    # ... other config
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/attacks"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 5s
```

## Docker CLI Access

You can also run attacks using the CLI tool inside the container:

```bash theme={null}
# Execute CLI commands
docker exec -it miku-miku-beam /app/mmb-cli attack http_flood http://example.com

# With custom parameters
docker exec -it miku-miku-beam /app/mmb-cli attack http_bypass http://example.com \
  --duration 120 \
  --delay 100 \
  --packet-size 1024 \
  --threads 8 \
  --verbose
```

## Production Optimization

<CodeGroup>
  ```dockerfile Optimized Dockerfile theme={null}
  # Use specific versions for reproducibility
  FROM node:18.19-alpine AS web-builder
  WORKDIR /app/web-client
  COPY web-client/package*.json ./
  RUN npm ci --only=production --no-audit --no-fund
  COPY web-client/ ./
  RUN npm run build

  FROM golang:1.21-alpine AS go-builder
  RUN apk add --no-cache git ca-certificates
  WORKDIR /app
  COPY go.mod go.sum ./
  RUN go mod download && go mod verify
  COPY . .
  RUN mkdir -p bin/web-client
  COPY --from=web-builder /app/web-client/dist/public/* bin/web-client/
  RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags='-w -s' \
      -o bin/mmb-server ./cmd/mmb-server
  RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags='-w -s' \
      -o bin/mmb-cli ./cmd/mmb-cli

  FROM alpine:latest
  RUN apk --no-cache add ca-certificates wget
  WORKDIR /app
  COPY --from=go-builder /app/bin/mmb-server /app/mmb-server
  COPY --from=go-builder /app/bin/mmb-cli /app/mmb-cli
  COPY --from=go-builder /app/bin/web-client /app/bin/web-client
  RUN mkdir -p /app/data && \
      addgroup -g 1000 mmb && \
      adduser -D -u 1000 -G mmb mmb && \
      chown -R mmb:mmb /app
  USER mmb
  EXPOSE 3000
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD wget --no-verbose --tries=1 --spider http://localhost:3000/attacks || exit 1
  CMD ["/app/mmb-server"]
  ```

  ```yaml Production Docker Compose theme={null}
  version: '3.8'

  services:
    mmb-server:
      build:
        context: .
        dockerfile: Dockerfile
      container_name: miku-miku-beam
      ports:
        - "3000:3000"
      volumes:
        - ./data:/app/data
        - ./config.toml:/app/config.toml:ro
      environment:
        - LOG_FORMAT=json
        - ALLOW_NO_PROXY=false
      restart: unless-stopped
      networks:
        - mmb-network
      healthcheck:
        test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/attacks"]
        interval: 30s
        timeout: 3s
        retries: 3
        start_period: 5s
      deploy:
        resources:
          limits:
            cpus: '2'
            memory: 2G
          reservations:
            cpus: '1'
            memory: 1G

  networks:
    mmb-network:
      driver: bridge
  ```
</CodeGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Container starts but web UI is not accessible">
    Check if the web client was built correctly:

    ```bash theme={null}
    docker exec miku-miku-beam ls -la /app/bin/web-client
    ```

    If empty, rebuild the image ensuring the web-client build stage completes successfully.
  </Accordion>

  <Accordion title="No proxies available error">
    Ensure the data volume is mounted correctly and contains proxies.txt:

    ```bash theme={null}
    docker exec miku-miku-beam cat /app/data/proxies.txt
    ```

    Or run with `ALLOW_NO_PROXY=true` to disable proxy requirement.
  </Accordion>

  <Accordion title="Permission denied errors">
    If using the non-root user setup, ensure proper permissions:

    ```bash theme={null}
    chmod -R 755 data/
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Production Deployment" icon="server" href="/deployment/production">
    Learn how to deploy MMB in production environments
  </Card>

  <Card title="Configuration" icon="gear" href="/configuration">
    Configure server settings and parameters
  </Card>
</CardGroup>
