Skip to content

Commit a5f2fac

Browse files
committed
chore: switch to host network mode for accurate analytics
- Update docker-compose.yml to use host network instead of port mapping - Install wget in Dockerfile for health check support - Remove EXPOSE directive as it's not needed for host network mode - Update README.md Docker deployment examples to use host network - Add bridge network alternative for development environments - Add warning about IP visibility in different network modes - Improve analytics accuracy by capturing real client IP addresses
1 parent 880eb52 commit a5f2fac

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ RUN pnpx rolldown --input ./scripts/migrate.ts --format esm --file ./.output/scr
2626
FROM node:24-alpine AS production
2727
WORKDIR /app
2828

29+
# Install wget for health check
30+
RUN apk add --no-cache wget
31+
2932
# Copy .output directory (which now contains migrate.mjs)
3033
COPY --from=build /app/.output /app
3134

@@ -34,5 +37,4 @@ ENV NODE_ENV=production
3437
ENV PORT=3000
3538

3639
# run the app
37-
EXPOSE 3000/tcp
3840
ENTRYPOINT ["sh", "-c", "node /app/scripts/migrate.mjs && node /app/server/index.mjs"]

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pnpm run preview
6262

6363
#### Docker Deployment
6464

65+
> **Note**: For accurate analytics and geolocation tracking, use `host` network mode. Bridge network mode may cause the application to receive Docker's internal IP instead of the real client IP, making analytics data less useful.
66+
6567
##### Option 1: Using Docker Compose (Recommended)
6668

6769
```bash
@@ -89,10 +91,10 @@ The application will be available at `http://localhost:3000`
8991
# Pull the official image
9092
docker pull demomacro/js.gs:latest
9193

92-
# Run container
94+
# Run container with host network
9395
docker run -d \
9496
--name js-gs \
95-
-p 3000:3000 \
97+
--network host \
9698
--env-file .env \
9799
--restart unless-stopped \
98100
demomacro/js.gs:latest
@@ -111,7 +113,15 @@ docker rm js-gs
111113
# Build Docker image
112114
docker build -t js.gs .
113115

114-
# Run container
116+
# Run container with host network (recommended)
117+
docker run -d \
118+
--name js-gs \
119+
--network host \
120+
--env-file .env \
121+
--restart unless-stopped \
122+
js.gs
123+
124+
# Or use bridge network with port mapping
115125
docker run -d \
116126
--name js-gs \
117127
-p 3000:3000 \

docker-compose.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
services:
22
app:
33
image: demomacro/js.gs:latest
4-
container_name: js-gs-app
54
restart: unless-stopped
6-
ports:
7-
- "3000:3000"
5+
network_mode: host
86
environment:
97
# Better Auth Configuration
108
BETTER_AUTH_URL: ${BETTER_AUTH_URL}
@@ -37,16 +35,18 @@ services:
3735

3836
# Node Environment
3937
NODE_ENV: production
40-
networks:
41-
- js-gs-network
38+
PORT: ${PORT:-3000}
4239
healthcheck:
43-
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/ok"]
40+
test:
41+
[
42+
"CMD",
43+
"wget",
44+
"--no-verbose",
45+
"--tries=1",
46+
"--spider",
47+
"http://localhost:${PORT:-3000}/api/ok",
48+
]
4449
interval: 30s
4550
timeout: 10s
4651
retries: 3
4752
start_period: 40s
48-
49-
networks:
50-
js-gs-network:
51-
driver: bridge
52-
name: js-gs-network

0 commit comments

Comments
 (0)