With this minimal Jenkins Pipeline script
node { docker.build("foo", "--build-arg x=y") }
I'm getting a confusing error
"docker build" requires exactly 1 argument(s).
But as per the documentation, the signature of docker.build()
is build(image[, args])
(from Jenkins /job/dockerbug/pipeline-syntax/globals#docker
)
build(image[, args])
Runs docker build to create and tag the specified image from a Dockerfile in the current directory. Additional args may be added, such as
'-f Dockerfile.other --pull --build-arg http_proxy=http://192.168.1.1:3128 .'
. Like docker build, args must end with the build context. Returns the resulting Image object. Records a FROM fingerprint in the build.
What's going on?
By default we provided dot(.) in the command which specifies the Docker daemon to use the shell's current working directory as the build context: $ docker build . In order to solve this issue, we need to provide the correct file name with -f option.
Dockerfile image building Note that the dot at the end tells the docker build command to look for the Dockerfile in the current directory.
Description. The docker build command builds Docker images from a Dockerfile and a “context”. A build's context is the set of files located in the specified PATH or URL . The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context ...
My confusion was because the error message is actually coming from Docker, not Jenkins.
Docker gives this error if you don't specify a build context (as noted in the docs above).
The fix is just to add .
to the end of the args parameter as per the example, eg:
node { docker.build("foo", "--build-arg x=y .") }
See docker: "build" requires 1 argument. See 'docker build --help'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With