Docker-compose syntax

Viewed 26
RUN if [ "$NODE_ENV" = "development" ]; \
        then npm install; \
        else npm install --only=production: \
        fi

When I try to run this code, I get that error message:

How can I fix that error?

 => ERROR [4/5] RUN if [ "development" = "development" ];         then npm install;         else npm install --only=production:         fi   
0.3s
------
 > [4/5] RUN if [ "development" = "development" ];         then npm install;         else npm install --only=production:         fi:
#8 0.291 /bin/sh: 1: Syntax error: end of file unexpected (expecting "fi")
------ executor failed running [/bin/sh -c if [ "$NODE_ENV" = "development" ];         then npm install;         else npm install
--only=production:         fi]: exit code: 2 ERROR: Service 'node-app' failed to build : Build failed
1 Answers

On the else line, there's a colon after --only=production, but I think you meant to use a semicolon instead:

RUN if [ "$NODE_ENV" = "development" ]; \
        then npm install; \
        else npm install --only=production; \
        fi
Related