On my dockerfile, I want to export a data from a json inside an env var. My issue is $(), don't work with jq How can I do-it?
MyDockerFile:
WORKDIR /myCurrentDir
RUN wget "http://stedolan.github.io/jq/download/linux64/jq"
RUN chmod 777 ./jq
RUN cat /myCurrentDir/build/BUILD_INFO.json | /myCurrentDir/jq '.version'
#work: return v1.23
RUN $(cat /myCurrentDir/build/BUILD_INFO.json | /myCurrentDir/jq '.version')
#don't work: /bin/sh: /myCurrentDir/jq: not found
I have try with jq instead of /myCurrentDir/jq, and./jq, it still don't work. ls show that jq is installed in /myCurrentDir
First of all, you haven't specified base image, so your Dockerfile is not reproducible.
I've tried this one:
FROM alpine
WORKDIR /myCurrentDir
RUN wget "http://stedolan.github.io/jq/download/linux64/jq"
RUN chmod 777 ./jq
RUN mkdir build && echo -e "{\"version\":\"v1.23\"}" > /myCurrentDir/build/BUILD_INFO.json
RUN cat /myCurrentDir/build/BUILD_INFO.json | /myCurrentDir/jq ".version"
And even at this stage I've got /bin/sh: /myCurrentDir/jq: not found
First, I suggest you to install jq
with the packet manager so that you don't have to worry about it's availability. And second, you could export your variable by specifying a file name in jq
command. For example, Dockerfile:
FROM alpine
WORKDIR /myCurrentDir
RUN apk add --no-cache jq
RUN mkdir build && echo -e "{\"version\":\"v1.23\"}" > /myCurrentDir/build/BUILD_INFO.json
RUN VER=$(jq '.version' /myCurrentDir/build/BUILD_INFO.json) && echo $VER > temp
To test that:
$ docker build -t test .
$ docker run test cat temp
"v1.23"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.