@@ -15,6 +15,7 @@ HOST_PORT=""
1515REDIS_HOST=" ${REDIS_HOST:- host.docker.internal} "
1616REDIS_PORT=" ${REDIS_PORT:- 6379} "
1717DAEMON_MODE=" "
18+ DOCKER_NETWORK=" autobox-network" # Default to autobox-network for Redis connectivity
1819
1920while [[ $# -gt 0 ]]; do
2021 case $1 in
@@ -42,6 +43,10 @@ while [[ $# -gt 0 ]]; do
4243 REDIS_PORT=" $2 "
4344 shift 2
4445 ;;
46+ --network|-n)
47+ DOCKER_NETWORK=" $2 "
48+ shift 2
49+ ;;
4550 --help|-h)
4651 echo " Usage: $0 [OPTIONS]"
4752 echo " "
@@ -50,8 +55,9 @@ while [[ $# -gt 0 ]]; do
5055 echo " -d, --daemon Keep server alive after simulation (default: false)"
5156 echo " -t, --tag TAG Docker image tag (default: latest)"
5257 echo " -p, --host-port PORT Host port to bind (default: auto-detect from server.json)"
53- echo " --redis-host HOST Redis host (default: host.docker.internal)"
58+ echo " --redis-host HOST Redis host (default: host.docker.internal, or 'redis' if using --network )"
5459 echo " --redis-port PORT Redis port (default: 6379)"
60+ echo " -n, --network NAME Docker network to join (default: autobox-network)"
5561 echo " -h, --help Show this help message"
5662 exit 0
5763 ;;
@@ -120,10 +126,70 @@ else
120126 PORT_ARGS=(-P)
121127fi
122128
129+ # If network is specified, ensure it exists and setup Redis
130+ if [ -n " $DOCKER_NETWORK " ]; then
131+ # Create network if it doesn't exist
132+ if ! docker network inspect " $DOCKER_NETWORK " & > /dev/null; then
133+ echo " Creating Docker network: $DOCKER_NETWORK "
134+ docker network create " $DOCKER_NETWORK "
135+ fi
136+
137+ # Check if Redis container exists and is running on this network
138+ if ! docker ps --format ' {{.Names}}' | grep -q " ^autobox-redis$" ; then
139+ # Check if Redis container exists but is stopped
140+ if docker ps -a --format ' {{.Names}}' | grep -q " ^autobox-redis$" ; then
141+ echo " Starting existing Redis container..."
142+ docker start autobox-redis
143+ # Connect to network if not already connected
144+ docker network connect " $DOCKER_NETWORK " autobox-redis 2> /dev/null || true
145+ else
146+ echo " Starting Redis container on network: $DOCKER_NETWORK "
147+ docker run -d \
148+ --name autobox-redis \
149+ --network " $DOCKER_NETWORK " \
150+ -p 6379:6379 \
151+ redis:alpine
152+ fi
153+ else
154+ # Redis is running, ensure it's on the network
155+ docker network connect " $DOCKER_NETWORK " autobox-redis 2> /dev/null || true
156+ fi
157+
158+ # Always wait for Redis to be ready
159+ echo " Waiting for Redis to be ready..."
160+ for i in {1..30}; do
161+ if docker exec autobox-redis redis-cli ping & > /dev/null; then
162+ echo " Redis is ready!"
163+ break
164+ fi
165+ sleep 1
166+ done
167+
168+ # Get Redis container IP for explicit host mapping (bypasses DNS)
169+ REDIS_IP=$( docker inspect -f ' {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' autobox-redis)
170+ if [ -z " $REDIS_IP " ]; then
171+ echo " Error: Could not get Redis container IP"
172+ exit 1
173+ fi
174+ echo " Redis IP: $REDIS_IP "
175+
176+ # Use 'redis' as hostname when on network
177+ if [ " $REDIS_HOST " = " host.docker.internal" ]; then
178+ REDIS_HOST=" redis"
179+ fi
180+ echo " Network: $DOCKER_NETWORK (Redis hostname: $REDIS_HOST -> $REDIS_IP )"
181+
182+ # Use explicit host mapping to bypass DNS
183+ NETWORK_ARGS=(--network " $DOCKER_NETWORK " --add-host " redis:$REDIS_IP " )
184+ else
185+ NETWORK_ARGS=()
186+ fi
187+
123188docker run \
124189 --rm \
125190 -it \
126191 " ${PORT_ARGS[@]} " \
192+ " ${NETWORK_ARGS[@]} " \
127193 -e OPENAI_API_KEY=" $OPENAI_API_KEY " \
128194 -e REDIS_HOST=" $REDIS_HOST " \
129195 -e REDIS_PORT=" $REDIS_PORT " \
@@ -133,6 +199,7 @@ docker run \
133199 -e JWT_EXPIRES_IN=" ${JWT_EXPIRES_IN:- 7d} " \
134200 -v " $( pwd) /examples/simulations:/app/examples/simulations:ro" \
135201 -v " $( pwd) /examples/metrics:/app/examples/metrics:ro" \
202+ -v " $( pwd) /examples/server:/app/examples/server:ro" \
136203 -v " $( pwd) /logs:/app/logs" \
137204 " autobox-engine:${IMAGE_TAG} " \
138205 --config=/app/examples \
0 commit comments