Is there a way to pass arguments to the docker bui...
# general
Is there a way to pass arguments to the docker build command during a
target invocation? Context is I need to pass networking mode and a host override to use an existing ssh tunnel. I see
but I don’t think those work for this
unfortunately no way to pass arbitrary command line args for
docker build
out of the box. If you’re adventurous you could create a
shim script and make pants pick that up forwarding your build request with any additional args as required.
k i guess that’ll hve to do for now
I imagine this is to make a shim, and use
to find it?
althgouh that seems to look for the actual binary? Trying to get a shim to a bash script does’nt seem to work
huh.. a
executable script named
on path ought to tick all the boxes we care about…
kk I’m probably not specifying it correctly.
I’ll have to try it out otherwise to be able to give clearer suggestions 😁
Copy code
$ ls -l /Users/nasron/gitroot/edge/pants-docker-shim/
total 16
-rwxr-xr-x  1 nasron  staff  128 30 Mar 17:20 docker
-rw-r--r--  1 nasron  staff  159 30 Mar 17:20 docker~
nasron aws:root py:3.9.10 (set by /Users/nasron/.pyenv/version) tf:tf:disabled ~/gitroot/edge on feature/EDGE-1519-fixing-pants-fl-server-client-docker
$ tail pants.toml

use_coverage = true

build_verbose = true
executable_search_paths = [
Copy code
BinaryNotFoundError: Cannot find `docker` on `['/Users/nasron/gitroot/edge/pants-docker-shim/']`. Please ensure that it is installed so that Pants can interact with the docker daemon.
👀 1
what’s in your shim file, as that is the only thing I can think of that might be different. (i.e. works for me)
Copy code
pants.engine.process.ProcessExecutionFailure: Process 'Building docker image test-example:1.2.5' failed with exit code 1.
DOCKER shim: build --pull=False --tag test-example:1.2.5 --file testprojects/src/python/docker/Dockerfile.example .

error: open .docker/buildx/instances/colima: no such file or directory
Copy code

echo "DOCKER shim: $@"
exec /opt/homebrew/bin/docker "$@"
fails on subsequent step as I don’t have the rest properly setup…
Ah I'm not using exec let me try that
An update on this, I ended up working around the actual tunnel, but I'm probably delaying the inevitable and may need to try the shim down the line.
I had a similar issue - wondered if it was hyphens in the file path, so moved the shim to a different and it worked. But then it worked when I moved it back to the original location. So suspect something with caching? Running with
might help?
Actually I think in the end it may have been that when the interpolation of options is incorrect, the 'BinaryNotFoundError' is raised, which is a bit misleading. In the end I came up with
Copy code
echo "Using Docker shim with args: $@"

if [ "$1" == "build" ]; then
  echo "Running build with '--network=host'"
  # Needed for GHA on EKS to set network mode.
  exec /usr/bin/docker build --network=host "$@"
  exit 0

exec /usr/bin/docker "$@"
👍 2
Hi! So coming back to this - is there a pants built in feature to pass args to the build command? Otherwise looks like I may have to try this shim as suggested.
For networking and hosts, support has been added directly now (I think since 2.18). See
👍 1
Ok, so I got this to work with in a rough way. Is there a way to provide a relative path for Or at least variables that can interpolate in the entries.
👍 1
I've not needed to set that - what are you hoping to achieve?
I’d like the shim to be part of the repo, so setting it relative to the repo location would be good.
right now I have a pre step to copy it to /tmp which is a bit janky
Another note that others may not have noticed - pants seems to test the docker binary with
docker -v
. If the binary doesn’t exit cleanly it appears as “no executable found” error. So I had to fake it in the shim for