|
37 | 37 |
|
38 | 38 | AGENT_CONTAINER="${AWF_AGENT_CONTAINER:-awf-agent}" |
39 | 39 |
|
40 | | -# Get the subcommand (first non-flag argument) |
| 40 | +# Known Docker subcommands that we need to intercept or handle. |
| 41 | +# Used by get_subcommand() to avoid misidentifying Docker global option |
| 42 | +# values as subcommands (e.g., `docker --context foo run` where `foo` is |
| 43 | +# a value for --context, not a subcommand). |
| 44 | +KNOWN_SUBCOMMANDS="run create exec build pull push images ps logs stop start rm rmi network compose volume inspect cp tag login logout info version" |
| 45 | + |
| 46 | +# Get the Docker subcommand, skipping global options and their values. |
| 47 | +# Docker global options that take a value (e.g., --context <name>, --host <url>) |
| 48 | +# would cause a naive "first non-flag token" parser to misidentify the value |
| 49 | +# as the subcommand. Instead, we check each non-flag token against known |
| 50 | +# Docker subcommands. |
41 | 51 | get_subcommand() { |
| 52 | + local skip_next=false |
42 | 53 | for arg in "$@"; do |
| 54 | + if [ "$skip_next" = true ]; then |
| 55 | + skip_next=false |
| 56 | + continue |
| 57 | + fi |
43 | 58 | case "$arg" in |
44 | | - -*) continue ;; |
45 | | - *) echo "$arg"; return ;; |
| 59 | + # Docker global options that take a separate value argument |
| 60 | + --config|--context|-c|--host|-H|--log-level|-l) |
| 61 | + skip_next=true |
| 62 | + continue |
| 63 | + ;; |
| 64 | + # Docker global options with value in same token (--context=foo) |
| 65 | + --config=*|--context=*|--host=*|--log-level=*) |
| 66 | + continue |
| 67 | + ;; |
| 68 | + # Other flags (boolean flags like --debug, --tls, etc.) |
| 69 | + -*) |
| 70 | + continue |
| 71 | + ;; |
| 72 | + *) |
| 73 | + # Check if this token is a known Docker subcommand |
| 74 | + for cmd in $KNOWN_SUBCOMMANDS; do |
| 75 | + if [ "$arg" = "$cmd" ]; then |
| 76 | + echo "$arg" |
| 77 | + return |
| 78 | + fi |
| 79 | + done |
| 80 | + # Unknown token before a known subcommand — skip it |
| 81 | + # (could be an unrecognized global option value) |
| 82 | + continue |
| 83 | + ;; |
46 | 84 | esac |
47 | 85 | done |
48 | 86 | } |
@@ -103,6 +141,7 @@ case "$SUBCOMMAND" in |
103 | 141 | # Propagate host.docker.internal DNS to child containers when host access is enabled. |
104 | 142 | # The agent container gets this via Docker's extra_hosts in docker-compose.yml, |
105 | 143 | # but child containers spawned via 'docker run' don't inherit it automatically. |
| 144 | + # Note: docker-manager.ts sets AWF_ENABLE_HOST_ACCESS='1' (not 'true'). |
106 | 145 | if [ "${AWF_ENABLE_HOST_ACCESS:-}" = "1" ]; then |
107 | 146 | INJECT_FLAGS+=("--add-host" "host.docker.internal:host-gateway") |
108 | 147 | fi |
|
0 commit comments