|
9 | 9 |
|
10 | 10 | ## Root Cause |
11 | 11 |
|
12 | | -**Docker Image Entrypoint Issue**: `alpine/git:latest` has `git` as the default entrypoint, not `sh`. This means: |
| 12 | +**Docker Image Entrypoint Issue**: `alpine/git:latest` has `git` as the default entrypoint, not `sh`. |
13 | 13 |
|
14 | | -- Local Docker might behave differently than CI |
15 | | -- Commands like `docker run alpine/git:latest "git init"` try to execute `git "git init"` instead of `sh -c "git init"` |
| 14 | +### Why Local vs CI Behaves Differently |
| 15 | + |
| 16 | +**Docker Runtime Environment Differences:** |
| 17 | + |
| 18 | +- **Local (Docker Desktop)**: More permissive, has compatibility layers that can "fix" some incorrect commands |
| 19 | +- **CI (Docker Engine)**: Stricter, follows Docker specifications exactly |
| 20 | + |
| 21 | +**Entrypoint Handling Differences:** |
| 22 | + |
| 23 | +```bash |
| 24 | +# What we were doing (WRONG): |
| 25 | +docker run alpine/git:latest "git init" |
| 26 | + |
| 27 | +# Local Docker Desktop might interpret this as: |
| 28 | +# -> Run git with argument "git init" |
| 29 | +# -> Sometimes works due to shell interpretation |
| 30 | + |
| 31 | +# CI Docker Engine interprets this as: |
| 32 | +# -> Run git "git init" (literally passes "git init" as argument to git) |
| 33 | +# -> Always fails: git doesn't understand "git init" as a single argument |
| 34 | +``` |
| 35 | + |
| 36 | +**Environment Masking:** |
| 37 | + |
| 38 | +- **Local**: Your shell might have different PATH, git configs, or environment variables that mask issues |
| 39 | +- **CI**: Clean, minimal environment exposes the exact Docker behavior |
| 40 | + |
| 41 | +**The Core Issue:** |
| 42 | +`alpine/git:latest` has `ENTRYPOINT ["git"]`, so: |
| 43 | + |
| 44 | +```bash |
| 45 | +# Without --entrypoint sh: |
| 46 | +docker run alpine/git:latest "some command" |
| 47 | +# Actually executes: git "some command" |
| 48 | +# ❌ This tries to run git with "some command" as a single argument |
| 49 | + |
| 50 | +# With --entrypoint sh: |
| 51 | +docker run --entrypoint sh alpine/git:latest -c "some command" |
| 52 | +# Actually executes: sh -c "some command" |
| 53 | +# ✅ This runs the command in shell properly |
| 54 | +``` |
16 | 55 |
|
17 | 56 | ## Complete Fix Pattern |
18 | 57 |
|
@@ -160,4 +199,11 @@ cargo test git --include-ignored |
160 | 199 | git push # Check GitHub Actions |
161 | 200 | ``` |
162 | 201 |
|
| 202 | +## Why This Bug Repeats |
| 203 | + |
| 204 | +1. **Local testing masks the issue** - Docker Desktop is more forgiving |
| 205 | +2. **The error is subtle** - Commands might partially work locally |
| 206 | +3. **CI environment is different** - Only fails in the strict CI environment |
| 207 | +4. **Git directory context** - After `git init`, subsequent commands need `--git-dir=.git` in containers |
| 208 | + |
163 | 209 | This bug has occurred multiple times - always refer to this guide when Docker git tests fail in CI but pass locally. |
0 commit comments