Search code examples
docker-composesh

How to run multiple lines command in docker compose?


I am trying to make this run but it retrieves this error:

fscrawler           | sed: -e expression #2, char 31: unknown option to `s'

I'm trying to run this command:

command: >
  sh -c "sed -i -e "s/{ELASTIC_PASSWORD}/${ELASTIC_PASSWORD}/g" 
  -e "s/{ELASTICSEARCH_HOST}/${ELASTICSEARCH_HOST}/g" 
  -e "s/{FSCRAWLER_HOST}/${FSCRAWLER_HOST}/g" /root/.fscrawler/job1/_settings.yaml 
  && fscrawler job1 --restart --rest"

I've tried with simple quotes and many other options (backslashes at the end as well) but couldn't make it work.


Solution

  • SOLUTION:

    docker-compose.yml

    entrypoint: /path/to/entrypoint.sh
    environment:
      - ELASTIC_HOST=${ELASTIC_HOST}
      - ELASTIC_USER=${ELASTIC_USER}
      - ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
      - FSCRAWLER_HOST=${FSCRAWLER_HOST}
    

    Dockerfile FSCrawler

    ...
    COPY /host/path/to/entrypoint.sh /docker/path/to/entrypoint.sh
    RUN chmod u+x /entrypoint.sh
    

    Entrypoint

    #!/bin/bash
    
    sed -i -e "s|{ELASTIC_USER}|${ELASTIC_USER}|g" \
    -e "s|{ELASTIC_PASSWORD}|${ELASTIC_PASSWORD}|g" \
    -e "s|{ELASTIC_HOST}|${ELASTIC_HOST}|g" \
    -e "s|{FSCRAWLER_HOST}|${FSCRAWLER_HOST}|g" /root/.fscrawler/job1/_settings.yaml 
    
    fscrawler job1 --restart --rest