kubectl create secret docker-registry $SECRET_NAME \
--dry-run=client \
--docker-server="$ECR_REGISTRY" \
--docker-username=AWS \
--docker-password="$(</token/ecr-token)" \
-o yaml
file token/ecr-token is in place but still not able to populate in --docker-password
The $(< /path/to/a/file)
syntax is a special form of command substitution that is supported by several UNIX shells, including ksh (Oracle online documentation), bash, and zsh. It attempts to open the listed file and then reads the contents of that file in place of the $(< ...)
. It is distinct from command substitution in that it does not execute the given file or its contents.
See more details at this UNIX & Linux Q/A: Understanding Bash's Read-a-File Command Substitution.
Note that your command specifies an absolute file path of /token/ecr-token
but then later describe a relative path of token/ecr-token
. If you're using a relative path in the command-line, that file will need to exist relative to your current working directory. Of course, the file must be readable by the current user for the contents to be read.
If your shell does not support this feature, a workaround is to use $(cat /path/to/a/file)
, for instance:
kubectl create secret docker-registry "$SECRET_NAME" \
--dry-run=client \
--docker-server="$ECR_REGISTRY" \
--docker-username=AWS \
--docker-password="$(cat /token/ecr-token)" \
-o yaml