Skip to content

Commit f9f4f9c

Browse files
committed
add docker
1 parent 3f911dd commit f9f4f9c

File tree

4 files changed

+283
-0
lines changed

4 files changed

+283
-0
lines changed

.dockerignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Git
2+
.git
3+
.gitignore
4+
5+
# Build artifacts
6+
build/
7+
8+
# Docker files
9+
Dockerfile
10+
docker-compose.yml
11+
.dockerignore
12+
README.docker.md
13+
14+
# Editor files
15+
.vscode/
16+
.idea/
17+
*.swp
18+
*.swo
19+
20+
# Temporary files
21+
*.tmp
22+
*.temp
23+
*.log
24+
25+
# OS specific files
26+
.DS_Store
27+
Thumbs.db

Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
FROM golang:1.24-alpine AS builder
2+
3+
# Set working directory
4+
WORKDIR /app
5+
6+
# Copy go.mod and go.sum files
7+
COPY go.mod ./
8+
9+
# Download dependencies
10+
RUN go mod download
11+
12+
# Copy the source code
13+
COPY . .
14+
15+
# Build the application
16+
RUN CGO_ENABLED=0 GOOS=linux go build -o reverse-soxy ./cmd/reverse-soxy
17+
18+
# Create a minimal image for running the application
19+
FROM alpine:latest
20+
21+
# Install ca-certificates for HTTPS connections
22+
RUN apk --no-cache add ca-certificates
23+
24+
# Create a non-root user
25+
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
26+
27+
# Set working directory
28+
WORKDIR /app
29+
30+
# Copy the binary from the builder stage
31+
COPY --from=builder /app/reverse-soxy .
32+
33+
# Create a directory for configuration files
34+
RUN mkdir -p /app/config && \
35+
chown -R appuser:appgroup /app
36+
37+
# Switch to non-root user
38+
USER appuser
39+
40+
# Expose ports
41+
# SOCKS5 proxy port
42+
EXPOSE 1080
43+
# Tunnel listen port
44+
EXPOSE 9000
45+
# Relay listen port
46+
EXPOSE 9000
47+
48+
# Set the entrypoint
49+
ENTRYPOINT ["/app/reverse-soxy"]
50+
51+
# Default command (can be overridden)
52+
CMD ["--proxy-listen-addr", "0.0.0.0:1080", "--tunnel-listen-port", "9000", "--secret", "changeme"]

README.docker.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Docker Setup for Reverse-SOXY
2+
3+
This document provides instructions for running Reverse-SOXY in Docker containers.
4+
5+
## Prerequisites
6+
7+
- [Docker](https://docs.docker.com/get-docker/)
8+
- [Docker Compose](https://docs.docker.com/compose/install/) (optional, for running multi-container setups)
9+
10+
## Building the Docker Image
11+
12+
To build the Docker image:
13+
14+
```bash
15+
docker build -t reverse-soxy .
16+
```
17+
18+
## Running with Docker
19+
20+
### Proxy Mode
21+
22+
```bash
23+
docker run -p 1080:1080 -p 9000:9000 reverse-soxy --proxy-listen-addr 0.0.0.0:1080 --tunnel-listen-port 9000 --secret yourSecretHere
24+
```
25+
26+
### Agent Mode
27+
28+
```bash
29+
docker run reverse-soxy --tunnel-addr proxy.host:9000 --secret yourSecretHere
30+
```
31+
32+
### Relay Mode
33+
34+
```bash
35+
docker run -p 9000:9000 reverse-soxy --mode relay --relay-listen-port 9000 --secret yourSecretHere
36+
```
37+
38+
### Proxy via Relay Mode
39+
40+
```bash
41+
docker run -p 1080:1080 reverse-soxy --mode proxy --register --relay-addr relay.host:9000 --proxy-listen-addr 0.0.0.0:1080 --secret yourSecretHere
42+
```
43+
44+
### Agent via Relay Mode
45+
46+
```bash
47+
docker run reverse-soxy --mode agent --relay-addr relay.host:9000 --secret yourSecretHere
48+
```
49+
50+
## Running with Docker Compose
51+
52+
The included `docker-compose.yml` file provides configurations for all modes of operation.
53+
54+
### Setting a Secure Secret
55+
56+
Before running, set a secure secret:
57+
58+
```bash
59+
export SECRET=yourSecretHere
60+
```
61+
62+
### Running Different Setups
63+
64+
#### Direct Proxy and Agent
65+
66+
```bash
67+
# Start the proxy
68+
docker-compose up proxy
69+
70+
# In another terminal, start the agent
71+
docker-compose up agent
72+
```
73+
74+
#### Relay Server with Proxy and Agent
75+
76+
```bash
77+
# Start the relay server
78+
docker-compose up relay
79+
80+
# In another terminal, start the proxy via relay
81+
docker-compose up proxy-via-relay
82+
83+
# In another terminal, start the agent via relay
84+
docker-compose up agent-via-relay
85+
```
86+
87+
## Configuration
88+
89+
### Environment Variables
90+
91+
- `SECRET`: The shared secret for encryption/authentication
92+
- `PROXY_HOST`: The hostname of the proxy (for agent mode)
93+
- `RELAY_HOST`: The hostname of the relay server (for proxy-via-relay and agent-via-relay modes)
94+
95+
### Custom Configuration File
96+
97+
You can mount a custom YAML configuration file:
98+
99+
```bash
100+
docker run -v /path/to/your/config.yml:/app/config/config.yml reverse-soxy --config /app/config/config.yml --secret yourSecretHere
101+
```
102+
103+
## Security Considerations
104+
105+
- Always use a strong, unique secret for each deployment
106+
- Consider using Docker secrets or environment variables for the secret in production
107+
- The default configuration exposes ports to all interfaces (0.0.0.0) within the container, so be careful with port mappings
108+
- In production, consider using a non-root user in the container
109+
110+
## Troubleshooting
111+
112+
### Debugging
113+
114+
Add the `--debug` flag to enable debug logging:
115+
116+
```bash
117+
docker run reverse-soxy --secret yourSecretHere --debug
118+
```
119+
120+
### Checking Container Logs
121+
122+
```bash
123+
docker logs <container_id>
124+
```
125+
126+
### Inspecting a Running Container
127+
128+
```bash
129+
docker exec -it <container_id> /bin/sh
130+
```

docker-compose.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
version: '3'
2+
3+
services:
4+
# Proxy mode service
5+
proxy:
6+
build: .
7+
ports:
8+
- "1080:1080" # SOCKS5 proxy port
9+
- "9000:9000" # Tunnel listen port
10+
environment:
11+
- SECRET=changeme # Change this to a secure secret
12+
command: >
13+
--proxy-listen-addr 0.0.0.0:1080
14+
--tunnel-listen-port 9000
15+
--secret ${SECRET:-changeme}
16+
--debug
17+
18+
# Agent mode service
19+
agent:
20+
build: .
21+
environment:
22+
- SECRET=changeme # Change this to a secure secret
23+
- PROXY_HOST=proxy # Change this to your proxy host if not using docker-compose networking
24+
command: >
25+
--tunnel-addr ${PROXY_HOST:-proxy}:9000
26+
--secret ${SECRET:-changeme}
27+
--debug
28+
depends_on:
29+
- proxy
30+
31+
# Relay mode service
32+
relay:
33+
build: .
34+
ports:
35+
- "9000:9000" # Relay listen port
36+
environment:
37+
- SECRET=changeme # Change this to a secure secret
38+
command: >
39+
--mode relay
40+
--relay-listen-port 9000
41+
--secret ${SECRET:-changeme}
42+
--debug
43+
44+
# Proxy via Relay mode service
45+
proxy-via-relay:
46+
build: .
47+
ports:
48+
- "1080:1080" # SOCKS5 proxy port
49+
environment:
50+
- SECRET=changeme # Change this to a secure secret
51+
- RELAY_HOST=relay # Change this to your relay host if not using docker-compose networking
52+
command: >
53+
--mode proxy
54+
--register
55+
--relay-addr ${RELAY_HOST:-relay}:9000
56+
--proxy-listen-addr 0.0.0.0:1080
57+
--secret ${SECRET:-changeme}
58+
--debug
59+
depends_on:
60+
- relay
61+
62+
# Agent via Relay mode service
63+
agent-via-relay:
64+
build: .
65+
environment:
66+
- SECRET=changeme # Change this to a secure secret
67+
- RELAY_HOST=relay # Change this to your relay host if not using docker-compose networking
68+
command: >
69+
--mode agent
70+
--relay-addr ${RELAY_HOST:-relay}:9000
71+
--secret ${SECRET:-changeme}
72+
--debug
73+
depends_on:
74+
- relay

0 commit comments

Comments
 (0)