0

Below commands in (tried in zsh and bash)

» docker build --label $(echo -n 'key="name value"') .
"docker build" requires exactly 1 argument.
See 'docker build --help'.

Usage:  docker build [OPTIONS] PATH | URL | -

Build an image from a Dockerfile

but if you try to check the actual command

» echo  docker build --label $(echo -n 'key="name value"') .
docker build --label key="name value" .

and then run it, it works. What am I missing

» docker build --label key="name value" .
Sending build context to Docker daemon  4.096kB
Step 1/2 : from busybox
 ---> 3a093384ac30
Step 2/2 : LABEL key=name value
 ---> Using cache
 ---> 8e0f5a40215e
Successfully built 8e0f5a40215e
ahmelsayed
  • 7,125
  • 3
  • 28
  • 40
  • 2
    You're running into [BashFAQ #50](http://mywiki.wooledge.org/BashFAQ/050). Command substitution results aren't parsed as syntax -- and it's a very good thing they aren't; it'd be impossible to write shell scripts processing untrusted data otherwise. – Charles Duffy Mar 22 '19 at 22:49
  • 1
    Note that when you run `docker build --label key="name value"`, the quotes aren't part of the command passed to Docker -- instead, they're part of the syntax recognized by the shell. That actual argument list passed to the operating system's `execve()` syscall looks something like (in C syntax) `char[][]{"docker", "build", "--label", "key=name value", NULL}` -- all the quotes did was ensure that the spaces be treated as literal. – Charles Duffy Mar 22 '19 at 22:54
  • Thanks for the explanation Charles. appreciate it and it makes sense. – ahmelsayed Mar 23 '19 at 03:26

0 Answers0