Inserting a conditional RUN statement inside a dockerfile

时间秒杀一切 提交于 2019-12-01 13:41:05

问题


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:

this is my simple 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:

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:


Just like when typing at the shell, you need either a newline or a semicolon before fi:

RUN if grep -q "grunt" package.json; then echo succeed; fi
                                             add this ^


来源:https://stackoverflow.com/questions/30156977/inserting-a-conditional-run-statement-inside-a-dockerfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!