0

I am using a container that allows to pass a command to be run during the entrypoint : the entrypoint does an exec $@.

I would like to run this command to add a line at the end of the config file :

cat /etc/program/config.yaml | grep "include: custom-config.yaml" || echo "include: custom-config.yaml" >> /etc/program/config.yaml

I'm trying to use it in docker-compose.yml like that :

command: ["/bin/bash", "-c", "'cat /etc/program/config.yaml | grep ''include: custom-config.yaml'' || echo ''include: custom-config.yaml'' >> /etc/program/config.yaml '"]

but this doesn't works

/etc/program/config.yaml: -c: line 1: syntax error: unexpected end of file
/etc/program/config.yaml: -c: line 0: unexpected EOF while looking for matching `''
/etc/program/config.yaml: -c: line 1: syntax error: unexpected end of file
/etc/program/config.yaml: -c: line 0: unexpected EOF while looking for matching `''
...

I think it might be caused by the pipe (see What is the use of the pipe symbol in YAML?), but I haven't been able to fix it

Thanks

Raphael
  • 27
  • 8
  • I may be ignorant about something but why the doubled single quotes `''` like in `... grep ''include...` ? – AymDev Jun 10 '21 at 08:42
  • It seems that it's the way to escape single quotes in single-quoted strings in yaml – Raphael Jun 10 '21 at 08:49
  • But your strings are double-quoted. And it seems like you forgot the `cat` command at the beginning. – AymDev Jun 10 '21 at 09:01

2 Answers2

3

I suggest you to create a script name run.sh like this:

#!/bin/bash

cat /etc/program/config.yaml | grep "include: custom-config.yaml" || echo "include: custom-config.yaml" >> /etc/program/config.yaml

Then create a docker file like the following:

FROM {{SOME_IMAGE}}

# ... some instructions ...

COPY run.sh .
CMD [ "run.sh" ]
Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • thanks, but unfortunately I don't have the liberty to create a new image, that's why i'm trying to workaround the existing one – Raphael Jun 10 '21 at 08:50
  • You say that cannot create a new image, but you want to fix the issue. In order to that, despite of the solution, you have to recreate the image. Or am I missing something? – Antonio Petricca Jun 10 '21 at 08:59
0

I finally created a script like that :

#!/bin/bash

cat /etc/program/config.yaml | grep "include: custom-config.yaml" || echo "include: custom-config.yaml" >> /etc/program/config.yaml

/docker-entrypoint.sh

and used it in the docker-compose file

entrypoint: /new_entrypoint.sh
Raphael
  • 27
  • 8