-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathdocker.sh
More file actions
executable file
·629 lines (576 loc) · 20.1 KB
/
docker.sh
File metadata and controls
executable file
·629 lines (576 loc) · 20.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
#!/bin/bash
set -o errexit -o pipefail -o noclobber -o nounset
# usually /home/trader/mmr
BUILDDIR=$(cd $(dirname "$0"); pwd)
# Detect container runtime.
# 1. Use whichever is already running.
# 2. If neither is running, try to start whichever is installed.
_setup_podman_compose() {
if podman compose version &> /dev/null; then
COMPOSE="podman compose"
elif command -v podman-compose &> /dev/null; then
COMPOSE="podman-compose"
else
echo "Error: podman found but no compose support."
echo "Install it with: pip3 install podman-compose"
exit 1
fi
}
_try_start_runtime() {
# Try Docker
if command -v docker &> /dev/null; then
echo "Docker found but not running. Attempting to start..."
if [[ "$(uname)" == "Darwin" ]]; then
open -a Docker 2>/dev/null || true
elif command -v systemctl &> /dev/null; then
sudo systemctl start docker 2>/dev/null || true
fi
for i in $(seq 1 30); do
if docker info &> /dev/null; then
echo "Docker started successfully."
RUNTIME=docker; COMPOSE="docker compose"; return 0
fi
sleep 1
done
fi
# Try Podman
if command -v podman &> /dev/null; then
echo "Podman found but not running. Attempting to start machine..."
podman machine start 2>/dev/null || { podman machine init 2>/dev/null && podman machine start 2>/dev/null; } || true
if podman info &> /dev/null; then
echo "Podman machine started successfully."
RUNTIME=podman; _setup_podman_compose; return 0
fi
fi
return 1
}
# Check what's already running first
if command -v docker &> /dev/null && docker info &> /dev/null; then
RUNTIME=docker
COMPOSE="docker compose"
elif command -v podman &> /dev/null && podman info &> /dev/null; then
RUNTIME=podman
_setup_podman_compose
elif ! _try_start_runtime; then
echo "Error: no working container runtime found."
echo " - docker: $(command -v docker &> /dev/null && echo 'installed' || echo 'not installed')"
echo " - podman: $(command -v podman &> /dev/null && echo 'installed' || echo 'not installed')"
echo ""
echo "Install Docker Desktop: https://docker.com/products/docker-desktop"
echo "Or install podman: brew install podman"
exit 1
fi
echo "Using container runtime: $RUNTIME"
# Where the host keeps DuckDBs, logs, TWS session state. Bind-mounted into
# the containers per docker-compose.yml — clobbering this dir wipes every
# sweep, backtest run, downloaded history bar, and IB session.
MMR_DATA_DIR="${HOME}/.local/share/mmr"
_human_size() {
# Cross-platform (macOS/Linux) human-readable size for one path.
# macOS's `du -h` doesn't have a `-d` flag with the same semantics as GNU,
# so we just shell out to -sh which works identically on both.
if [ -e "$1" ]; then
du -sh "$1" 2>/dev/null | awk '{print $1}'
else
echo "-"
fi
}
print_data_sizes() {
# Show what's on disk right up front so anyone running a destructive
# action knows the scope of what they could lose.
local data_db="$MMR_DATA_DIR/data/mmr.duckdb"
local hist_db="$MMR_DATA_DIR/data/mmr_history.duckdb"
local logs_dir="$MMR_DATA_DIR/logs"
local tws_dir="$MMR_DATA_DIR/tws_settings"
echo "Host data at $MMR_DATA_DIR:"
[ -e "$data_db" ] && echo " mmr.duckdb: $(_human_size "$data_db") (sweeps, backtests, proposals, universes)"
[ -e "$hist_db" ] && echo " mmr_history.duckdb: $(_human_size "$hist_db") (1-min / 1-day OHLCV)"
[ -e "$logs_dir" ] && echo " logs/: $(_human_size "$logs_dir")"
[ -e "$tws_dir" ] && echo " tws_settings/: $(_human_size "$tws_dir") (IB session state)"
if [ ! -d "$MMR_DATA_DIR" ]; then
echo " (no data dir yet — first run will create it)"
fi
echo ""
}
print_data_sizes
# Required RAM (bytes) for the full MMR stack. Set by the mem_limit values
# in docker-compose.yml (4 GB mmr + 1.5 GB ib-gateway = 5.5 GB minimum;
# leave 2 GB headroom for the VM/kernel, so ~8 GB is the target).
MIN_VM_RAM_MB=6144
RECOMMENDED_VM_RAM_MB=8192
check_vm_ram() {
# On macOS, Docker Desktop + Podman both run a Linux VM with its own
# RAM budget — the Mac has plenty but the VM cap is what the
# containers actually see. A 2 GB default (Podman applehv's out-of-box
# setting) has OOM-killed trader_service + strategy_service mid-order;
# warn loudly when we find it. On Linux, check host RAM directly.
local ram_mb=0
local source=""
if [[ "$(uname)" == "Darwin" ]]; then
if [[ "$RUNTIME" == "podman" ]]; then
ram_mb=$(podman machine inspect 2>/dev/null \
| awk -F'[:,]' '/"Memory"/ { gsub(/[^0-9]/,"",$2); print $2; exit }')
source="podman machine"
elif [[ "$RUNTIME" == "docker" ]]; then
local mem_bytes
mem_bytes=$(docker info --format '{{.MemTotal}}' 2>/dev/null || echo 0)
if [ -n "$mem_bytes" ] && [ "$mem_bytes" -gt 0 ]; then
ram_mb=$((mem_bytes / 1024 / 1024))
fi
source="Docker Desktop VM"
fi
else
if command -v free &> /dev/null; then
ram_mb=$(free -m | awk '/^Mem:/ {print $2}')
source="host"
fi
fi
if [ -z "$ram_mb" ] || [ "$ram_mb" -le 0 ]; then
echo "Warning: couldn't determine ${source:-VM} RAM — skipping sizing check."
echo ""
return 0
fi
if [ "$ram_mb" -lt "$MIN_VM_RAM_MB" ]; then
echo "=============================================================="
echo " RAM WARNING: $source has ${ram_mb} MB (minimum ${MIN_VM_RAM_MB} MB)"
echo "=============================================================="
echo " trader_service + strategy_service have been OOM-killed in"
echo " production at 2 GB. Recommended: ${RECOMMENDED_VM_RAM_MB} MB."
if [[ "$(uname)" == "Darwin" && "$RUNTIME" == "podman" ]]; then
echo ""
echo " To resize the Podman VM (requires restart):"
echo " podman machine stop"
echo " podman machine set --memory ${RECOMMENDED_VM_RAM_MB}"
echo " podman machine start"
elif [[ "$(uname)" == "Darwin" && "$RUNTIME" == "docker" ]]; then
echo ""
echo " Open Docker Desktop → Settings → Resources → Memory,"
echo " bump to ${RECOMMENDED_VM_RAM_MB} MB or more."
fi
echo ""
if [ -t 0 ] && [ -t 1 ]; then
read -p "Continue anyway? [y/N]: " answer
case "${answer:-n}" in
y|Y|yes) ;;
*) echo "Aborting. Resize and re-run."; exit 1 ;;
esac
else
echo "(non-interactive, continuing — rebuild is up to you)"
fi
echo ""
else
echo "$source RAM: ${ram_mb} MB (>= ${MIN_VM_RAM_MB} MB required) ✓"
echo ""
fi
}
check_vm_ram
print_vnc_url() {
# Print a clickable vnc:// URL for the IB Gateway desktop.
# macOS Terminal and iTerm2 auto-link the vnc:// scheme (⌘-click opens
# Screen Sharing). Password is not embedded in the URL — it would land
# in scrollback/logs.
local prefix="${1:-}"
# Compose defaults VNC_SERVER_PASSWORD to "trader" when unset.
local vnc_pass="trader"
if [ -f "$BUILDDIR/.env" ]; then
local from_env
from_env=$(grep -E '^VNC_SERVER_PASSWORD=' "$BUILDDIR/.env" 2>/dev/null | cut -d= -f2- || echo "")
if [ -n "$from_env" ]; then
vnc_pass="$from_env"
fi
fi
echo "${prefix}IB Gateway VNC: vnc://localhost:5901"
if [ "$vnc_pass" = "trader" ]; then
echo "${prefix} (password: trader)"
else
echo "${prefix} (password: see VNC_SERVER_PASSWORD in .env)"
fi
}
echo_usage() {
echo "usage: docker.sh -- helper script to manage MMR + IB Gateway containers"
echo
echo " Uses docker-compose with IB Gateway sidecar container."
echo " Supports both docker and podman (auto-detected)."
echo
echo " -b (build MMR image)"
echo " -u (up: start all containers — IB Gateway + MMR)"
echo " -i (ib-only: start only IB Gateway for local development)"
echo " -d (down: stop and remove all containers)"
echo " -c (clean: remove all images and containers)"
echo " -f (force clean: images + containers + build cache + HOST DATA"
echo " — prompts for confirmation before wiping sweeps/backtests/history;"
echo " set MMR_FORCE_CLEAN_KEEP_DATA=1 to skip the data wipe)"
echo " -s (sync code to running MMR container)"
echo " -a (sync all files to running MMR container)"
echo " -g (go: build, then start all containers and exec in)"
echo " -l (logs: tail logs from all containers)"
echo " -r (restart-ib: restart the IB Gateway container)"
echo " -e (exec: shell into running MMR container)"
echo ""
}
b=n c=n f=n u=n d=n s=n a=n g=n l=n e=n i=n r=n
while [[ $# -gt 0 ]]; do
case $1 in
-b|--build)
b=y
shift
;;
-u|--up)
u=y
shift
;;
-d|--down)
d=y
shift
;;
-c|--clean)
c=y
shift
;;
-f|--force)
f=y
shift
;;
-g|--go)
g=y
shift
;;
-s|--sync)
s=y
shift
;;
-a|--sync_all)
a=y
shift
;;
-l|--logs)
l=y
shift
;;
-e|--exec)
e=y
shift
;;
-i|--ib-only)
i=y
shift
;;
-r|--restart-ib)
r=y
shift
;;
-*|--*)
echo "Unknown option $1"
echo_usage
exit 1
;;
*)
shift
;;
esac
done
# show usage if no action flags were set
if [[ $b == "n" && $c == "n" && $f == "n" && $u == "n" && $d == "n" && $s == "n" && $a == "n" && $g == "n" && $l == "n" && $e == "n" && $i == "n" && $r == "n" ]]; then
echo_usage
exit 0
fi
# Prompt for IB credentials and write .env file
setup_credentials() {
echo ""
echo "============================================================"
echo " MMR First-Time Setup"
echo "============================================================"
echo ""
local userid password account trading_mode vnc_password timezone
read -p "Interactive Brokers username: " userid
read -s -p "Interactive Brokers password: " password
echo ""
read -p "IB account number (U... for live, DU... for paper): " account
echo ""
echo "Trading mode:"
echo " 1) paper (default)"
echo " 2) live"
read -p "Select [1]: " mode_choice
case "${mode_choice:-1}" in
2|live) trading_mode="live" ;;
*) trading_mode="paper" ;;
esac
read -p "Timezone [America/New_York]: " timezone
timezone="${timezone:-America/New_York}"
read -p "VNC password for IB Gateway GUI [trader]: " vnc_password
vnc_password="${vnc_password:-trader}"
cat > "$BUILDDIR/.env" <<EOF
# MMR Configuration — generated by docker.sh
# Edit this file to change credentials or settings.
# IB Gateway credentials
TWS_USERID=${userid}
TWS_PASSWORD=${password}
# Trading mode: paper or live
TRADING_MODE=${trading_mode}
# IB account number
IB_ACCOUNT=${account}
# Timezone
TIME_ZONE=${timezone}
# VNC password for IB Gateway GUI (default: "trader"; bound to 127.0.0.1:5901 only)
VNC_SERVER_PASSWORD=${vnc_password}
# IB Gateway settings
TWS_ACCEPT_INCOMING=accept
READ_ONLY_API=no
TWOFA_TIMEOUT_ACTION=restart
RELOGIN_AFTER_TWOFA_TIMEOUT=yes
EXISTING_SESSION_DETECTED_ACTION=primaryoverride
AUTO_RESTART_TIME="11:59 PM"
ALLOW_BLIND_TRADING=no
EOF
echo ""
echo "Credentials saved to $BUILDDIR/.env"
echo "You can edit this file later to change settings."
echo ""
}
# check for .env file, prompt if missing or incomplete
check_env() {
if [ ! -f "$BUILDDIR/.env" ]; then
setup_credentials
fi
# Check if credentials are filled in
source "$BUILDDIR/.env"
if [ -z "${TWS_USERID:-}" ] || [ -z "${TWS_PASSWORD:-}" ]; then
echo "IB credentials are not set in .env"
read -p "Set up credentials now? [Y/n]: " answer
case "${answer:-y}" in
n|N|no) echo "Skipping — IB Gateway will not be able to log in." ;;
*) setup_credentials ;;
esac
fi
}
build() {
echo "Building MMR image..."
echo ""
$COMPOSE -f "$BUILDDIR/docker-compose.yml" build mmr
}
up() {
check_env
echo "Pulling latest IB Gateway image..."
$COMPOSE -f "$BUILDDIR/docker-compose.yml" pull ib-gateway
echo ""
echo "Starting IB Gateway + MMR containers..."
echo ""
# Ensure bind-mount directories exist on host
mkdir -p "$HOME/.local/share/mmr/data" "$HOME/.local/share/mmr/logs" "$HOME/.local/share/mmr/tws_settings"
# Remove stale network to avoid label mismatch errors (podman/docker-compose compat).
# Must remove containers using the network first, then the network itself.
for cid in $($RUNTIME ps -a -q --filter network=mmr_default 2>/dev/null); do
$RUNTIME rm -f "$cid" 2>/dev/null || true
done
$RUNTIME network rm mmr_default 2>/dev/null || true
# Belt-and-suspenders: also sweep any mmr-mmr / mmr_mmr containers that
# somehow aren't attached to mmr_default (e.g. left over from a previous
# run on a different network name). Without this, `./docker.sh -g`
# can't recover from the stuck-dependent state described in
# `_remove_mmr_dependents`.
_remove_mmr_dependents
$COMPOSE -f "$BUILDDIR/docker-compose.yml" up -d
echo ""
echo "Containers started. Use './docker.sh -e' to exec in, or './docker.sh -l' for logs."
print_vnc_url
}
# Force-recreate fails when other compose services (e.g. mmr_mmr_1 from a
# previous `./docker.sh -u`) still exist with `depends_on: ib-gateway` —
# podman/docker refuse to remove ib-gateway while a dependent is around,
# leaving the old ib-gateway stopped and nothing listening on 7497/7496.
# Sweep dependents before recreating.
_remove_mmr_dependents() {
for cid in $($RUNTIME ps -aq --filter "name=mmr[-_]mmr" 2>/dev/null); do
$RUNTIME rm -f "$cid" 2>/dev/null || true
done
}
ib_only() {
check_env
echo "Pulling latest IB Gateway image..."
$COMPOSE -f "$BUILDDIR/docker-compose.yml" pull ib-gateway
echo ""
echo "Starting IB Gateway only (for local development)..."
echo ""
_remove_mmr_dependents
# Force recreate so .env changes are always picked up
$COMPOSE -f "$BUILDDIR/docker-compose.yml" up -d --force-recreate ib-gateway
echo ""
source "$BUILDDIR/.env"
# Host-side port the user connects to. docker-compose.yml maps
# 7496->container:4003 (live) and 7497->container:4004 (paper).
# IB Gateway itself listens on 4001/4002 internally; gnzsnz's socat
# forwards 4003/4004 -> 4001/4002. Don't echo the internal ports —
# nothing on the host can reach them.
local ib_port
if [ "${TRADING_MODE:-paper}" = "paper" ]; then
ib_port=7497
else
ib_port=7496
fi
echo "IB Gateway running."
echo " API: localhost:$ib_port (${TRADING_MODE:-paper})"
print_vnc_url " "
echo ""
echo "Configure your local trader.yaml:"
echo " ib_server_address: 127.0.0.1"
echo " ib_server_port: $ib_port"
echo ""
echo "Or run services directly:"
echo " python3 -m trader.trader_service"
echo " python3 -m trader.strategy_service"
echo " python3 -m trader.mmr_cli"
}
restart_ib() {
echo "Restarting IB Gateway container..."
# Same dependent-container guard as ib_only(): podman/docker won't
# recreate ib-gateway while a container with `depends_on: ib-gateway`
# exists, even if it's stopped.
_remove_mmr_dependents
$COMPOSE -f "$BUILDDIR/docker-compose.yml" up -d --force-recreate ib-gateway
echo ""
echo "IB Gateway restarted."
}
down() {
echo "Stopping all containers..."
$COMPOSE -f "$BUILDDIR/docker-compose.yml" down 2>/dev/null || true
# Remove stale network to avoid label mismatch errors (podman/docker-compose compat)
for cid in $($RUNTIME ps -a -q --filter network=mmr_default 2>/dev/null); do
$RUNTIME rm -f "$cid" 2>/dev/null || true
done
$RUNTIME network rm mmr_default 2>/dev/null || true
}
clean() {
echo "Stopping and removing all containers and images..."
$COMPOSE -f "$BUILDDIR/docker-compose.yml" down --rmi all --volumes 2>/dev/null || true
}
force_clean() {
clean
echo "Cleaning build cache..."
if [[ "$RUNTIME" == "docker" ]]; then
docker builder prune --force
else
podman system prune --force
fi
# Host data is bind-mounted, so docker-level cleanup NEVER touches it —
# if the user asked for force-clean they probably want a true reset, so
# confirm the scope and wipe. Skipping when MMR_FORCE_CLEAN_KEEP_DATA=1
# lets CI/automation keep the "build-cache-only" behaviour if needed.
if [ "${MMR_FORCE_CLEAN_KEEP_DATA:-0}" = "1" ]; then
echo "MMR_FORCE_CLEAN_KEEP_DATA=1 — keeping host data at $MMR_DATA_DIR"
return
fi
if [ ! -d "$MMR_DATA_DIR" ]; then
return
fi
echo ""
echo "=============================================================="
echo " WIPE HOST DATA?"
echo "=============================================================="
echo " This will DELETE all sweeps, backtest runs, proposals,"
echo " universes, downloaded OHLCV history, IB session state, and"
echo " logs at:"
echo ""
echo " $MMR_DATA_DIR ($(_human_size "$MMR_DATA_DIR"))"
echo ""
echo " This is NOT recoverable. Container images + build cache are"
echo " already gone at this point; skipping now leaves only the"
echo " data behind for a fresh rebuild on next start."
echo ""
read -p "Type 'DELETE' to confirm (anything else aborts): " confirm
if [ "$confirm" = "DELETE" ]; then
echo "Removing $MMR_DATA_DIR..."
rm -rf "$MMR_DATA_DIR"
echo "Host data wiped."
else
echo "Keeping host data. (Tip: MMR_FORCE_CLEAN_KEEP_DATA=1 skips this prompt.)"
fi
}
logs() {
$COMPOSE -f "$BUILDDIR/docker-compose.yml" logs -f
}
exec_in() {
CONTID="$($RUNTIME ps -aqf name=mmr-mmr)"
if [[ -z "$CONTID" ]]; then
CONTID="$($RUNTIME ps -aqf name=mmr_mmr || true)"
fi
if [[ -z "$CONTID" ]]; then
echo "Can't find running MMR container"
exit 1
fi
echo "Exec'ing into MMR container ($CONTID)..."
$RUNTIME exec -it -u trader -w /home/trader/mmr "$CONTID" bash -l
}
sync() {
echo "Syncing code directory to MMR container..."
echo ""
CONTID="$($RUNTIME ps -aqf name=mmr-mmr)"
if [[ -z "$CONTID" ]]; then
# try alternate name patterns
CONTID="$($RUNTIME ps -aqf name=mmr_mmr || true)"
fi
if [[ -z "$CONTID" ]]; then
echo "Can't find running MMR container"
exit 1
fi
echo "container id: $CONTID"
RSYNC_RSH="$RUNTIME exec -i"
rsync -e "$RSYNC_RSH" -av --delete $BUILDDIR/ $CONTID:/home/trader/mmr/ --exclude='.git' --filter="dir-merge,- .gitignore"
}
sync_all() {
echo "Syncing entire mmr directory to MMR container..."
echo ""
CONTID="$($RUNTIME ps -aqf name=mmr-mmr)"
if [[ -z "$CONTID" ]]; then
CONTID="$($RUNTIME ps -aqf name=mmr_mmr || true)"
fi
if [[ -z "$CONTID" ]]; then
echo "Can't find running MMR container"
exit 1
fi
echo "container id: $CONTID"
RSYNC_RSH="$RUNTIME exec -i"
rsync -e "$RSYNC_RSH" -av --delete $BUILDDIR/ $CONTID:/home/trader/mmr/ --exclude='.git'
}
echo "action: build=$b clean=$c force=$f up=$u down=$d sync=$s sync_all=$a go=$g logs=$l exec=$e ib-only=$i restart-ib=$r | runtime: $RUNTIME"
if [[ $b == "y" ]]; then
build
fi
if [[ $d == "y" ]]; then
down
fi
if [[ $c == "y" ]]; then
clean
fi
if [[ $f == "y" ]]; then
force_clean
fi
if [[ $u == "y" ]]; then
up
fi
if [[ $i == "y" ]]; then
ib_only
fi
if [[ $r == "y" ]]; then
restart_ib
fi
if [[ $s == "y" ]]; then
sync
fi
if [[ $a == "y" ]]; then
sync_all
fi
if [[ $l == "y" ]]; then
logs
fi
if [[ $e == "y" ]]; then
exec_in
fi
if [[ $g == "y" ]]; then
build
down 2>/dev/null || true
up
echo ""
echo "Waiting for containers to start..."
sleep 3
exec_in
fi