Reputation: 47
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
Upvotes: 0
Views: 1612
Reputation: 47
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
Upvotes: 0
Reputation: 11006
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" ]
Upvotes: 3