I am trying to write a docker file which will run a RUN command to search for a word in a package.json file and act upon it:
我正在尝试编写一个docker文件,它将运行一个RUN命令来搜索package.json文件中的一个单词并对其进行操作:
this is my simple dockerfile:
这是我简单的dockerfile:
FROM ubuntu:14.04
COPY package.json package.json
RUN if grep -q "grunt" package.json; then echo succeed fi
as you can see i just want a simple if statement but it get this error:
正如你所看到的,我只想要一个简单的if语句,但它会出现这个错误:
Step 2 : RUN if grep -q "grunt" package.json; then echo succeed fi
---> Running in af460df45239
/bin/sh: 1: Syntax error: end of file unexpected (expecting "fi")
INFO[0001] The command [/bin/sh -c if grep -q "grunt" package.json; then echo succeed fi] returned a non-zero code: 2
How should i run my command? thanks.
我应该如何运行我的命令?谢谢。
1 个解决方案
#1
46
Just like when typing at the shell, you need either a newline or a semicolon before fi
:
就像在shell中输入一样,在fi之前需要换行符或分号:
RUN if grep -q "grunt" package.json; then echo succeed; fi
add this ^
#1
46
Just like when typing at the shell, you need either a newline or a semicolon before fi
:
就像在shell中输入一样,在fi之前需要换行符或分号:
RUN if grep -q "grunt" package.json; then echo succeed; fi
add this ^