Commit ec01475
feat: smart CMD/ENTRYPOINT detection for all container backends
Problem:
- Images with interactive shells (bash/sh) as CMD exit immediately without -it
- PyTorch, TensorFlow, Ubuntu, Alpine images all use /bin/bash or /bin/sh
- Containers start then immediately stop, causing "container not running" errors
- Previous code blindly used sleep infinity, overriding useful CMDs like Jupyter
- Each backend needs platform-specific handling (Docker, Colima, WSL, Apple)
Solution:
Implemented intelligent CMD detection across all 4 backends:
1. **Shared Detection Logic (container_setup.go:517-559)**
- ImageHasDefaultCommand() - inspects image CMD/ENTRYPOINT
- Detects interactive shells: /bin/bash, /bin/sh (all variants)
- Excludes scripts: "start-*", "*.sh" are treated as services
- Safe fallback: inspection errors → assume no useful CMD
2. **Docker Backend (backend_docker.go:313-327)**
- Uses ImageHasDefaultCommand(ctx, b.dockerCmd, image)
- Interactive shell → sleep infinity
- Service script → use image default
3. **Colima Backend (backend_colima.go:507-534)**
- Uses ImageHasDefaultCommand(ctx, "docker", image)
- Same logic with Colima docker context
4. **WSL Backend (backend_wsl.go:318-361)**
- Inline implementation (runs docker inspect in WSL)
- Same shell detection logic
- Special handling for WSL execution context
5. **Apple Container Backend (backend_apple.go:211-232)**
- Uses ImageHasDefaultCommand(ctx, b.containerCmd, image)
- Added klog import for logging
- Works with container (not docker) command
Results by Image Type:
- pytorch/pytorch [/bin/bash][] → sleep infinity ✓
- jupyter/scipy-notebook [start-notebook.py][tini] → use default ✓
- ubuntu [/bin/bash][] → sleep infinity ✓
- alpine [/bin/sh][] → sleep infinity ✓
- tensorflow/tensorflow [/bin/bash][] → sleep infinity ✓
- Custom with scripts [start.sh][] → use default ✓
Platform Coverage:
- ✅ Linux (Docker)
- ✅ macOS (Docker Desktop)
- ✅ macOS (Colima)
- ✅ macOS 26+ (Apple Container)
- ✅ Windows (Docker Desktop)
- ✅ Windows (WSL2 + Docker)
Changes:
- container_setup.go: Add ImageHasDefaultCommand() + os/exec import
- backend_docker.go: Use smart detection before adding CMD
- backend_colima.go: Use smart detection before adding CMD
- backend_wsl.go: Inline detection with WSL context handling
- backend_apple.go: Use smart detection + add klog import
This ensures containers stay running across all platforms while
respecting useful default commands like Jupyter's start-notebook.py.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 7ee9d8b commit ec01475
5 files changed
Lines changed: 133 additions & 24 deletions
File tree
- internal/studio
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
215 | 216 | | |
216 | 217 | | |
217 | 218 | | |
218 | | - | |
219 | | - | |
220 | | - | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
221 | 235 | | |
222 | 236 | | |
223 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | 514 | | |
521 | 515 | | |
522 | 516 | | |
523 | 517 | | |
524 | 518 | | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
525 | 537 | | |
526 | 538 | | |
527 | 539 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | 306 | | |
318 | 307 | | |
319 | 308 | | |
320 | 309 | | |
321 | 310 | | |
322 | 311 | | |
323 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
324 | 331 | | |
325 | 332 | | |
326 | 333 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
| 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 | + | |
329 | 363 | | |
330 | 364 | | |
331 | 365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
501 | 502 | | |
502 | 503 | | |
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 | + | |
0 commit comments