Adding command lines in RUN (Dockerfile)

I would like to create my own image of Nagios (I am getting started using some of the Dockerfile from jasonrivers\nagios image)

My Dockerfile apparently is not correctly formatted and I am not sure why

Here is the line that throws an error

RUN /bin/sh -c (egrep -i '^${NAGIOS_GROUP}' /etc/group || groupadd $NAGIOS_GROUP) && (egrep -i '^${NAGIOS_CMDGROUP}' /etc/group || groupadd $NAGIOS_CMDGROUP)

And the error:

 => ERROR [ 3/28] RUN /bin/sh -c (egrep -i '^${NAGIOS_GROUP}' /etc/group || groupadd nagios) && (egrep -i '^${NAGIOS_CMDGROUP}' /etc/group || groupadd nagios)                                                                    0.1s
------                                                                                                                                                                                                                                 
 > [ 3/28] RUN /bin/sh -c (egrep -i '^${NAGIOS_GROUP}' /etc/group || groupadd nagios) && (egrep -i '^${NAGIOS_CMDGROUP}' /etc/group || groupadd nagios):
0.079 /bin/sh: 1: Syntax error: "(" unexpected
------
Dockerfile:43
--------------------
  41 |     	
  42 |     	#NAGIOS GROUP & USER 
  43 | >>> 	RUN /bin/sh -c (egrep -i '^${NAGIOS_GROUP}' /etc/group || groupadd $NAGIOS_GROUP) && (egrep -i '^${NAGIOS_CMDGROUP}' /etc/group || groupadd $NAGIOS_CMDGROUP)
  44 |     	RUN /bin/sh -c ( id -u $NAGIOS_USER || useradd --system -d $NAGIOS_HOME -g $NAGIOS_GROUP $NAGIOS_USER ) \
  45 |     	&& ( id -u $NAGIOS_CMDUSER || useradd --system -d $NAGIOS_HOME -g $NAGIOS_CMDGROUP $NAGIOS_CMDUSER )
--------------------
ERROR: failed to solve: process "/bin/sh -c /bin/sh -c (egrep -i '^${NAGIOS_GROUP}' /etc/group || groupadd $NAGIOS_GROUP) && (egrep -i '^${NAGIOS_CMDGROUP}' /etc/group || groupadd $NAGIOS_CMDGROUP)" did not complete successfully: exit code: 2

You have a syntax error. It has nothing to do with containers. It would not work outside of containers either. You need to pass the commands correctly to the shell. But why do you add /bin/sh in the first place? Everything in a RUN instruction is executed in a shell by default. You can even controll what shell it is by setting the SHELL instruction.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.