I would like to populate a entry in config file at run time via docker compose

I have tomcat installed in a container, inside it there is application configuration file. I would like to populate a value inside it during run time. (before that I dont know what the value so cant populate at the time of building the image)

I am invoking service with docker-compose up, and I would like the value in configuration file gets replaced via the value I provide to docker compose as parameter

  • Windows Container on Windows 10 Insider Build and Docker for Windows
  • Java Development in Dockerized environment: Debugging And hot code reload
  • Docker in host mode cannot connect to database running on host
  • How to connect to SSHD inside a Docker container from Windows?
  • Error looking up volume plugin flocker: plugin not found in docker
  • Jenkins Mesos — Error: Unable to access jarfile
  • something like docker-compose up -e “value at run time via docker compose”

     URL for server
     SERVERADD=https://{{value at run time via docker compose}}/{{index}} 
    

    Can I accomplish this with environment variable or any other way kindly suggest !!!

  • Docker Postgress Clear all Data
  • Run multiple containers on same docker network localhost
  • Docker and bower links
  • Why it'll abort when I add `RUN ln -sf /dev/stderr /var/log/mysql/error.log` to mysql dockerfile?
  • MongoDB in Docker container runs out of space for journal
  • Active directory accounts inside a windows container (server 2016 TP5)
  • One Solution collect form web for “I would like to populate a entry in config file at run time via docker compose”

    This is normally done in an ENTRYPOINT or CMD script that is built into the image.

    The script checks for the environment variable, does the replacements or other work required, then continues on to run the command as before.

    #!/bin/sh
    if [ -n "$SOME_ENV" ]; then
      sed -i '' -e 's/^param=.*/param='"$SOME_ENV"'/' /etc/file.conf
    fi
    exec "$@"
    

    The script needs to be added to an image, the Dockerfile could be:

    FROM whatever
    COPY docker-entrypoint.sh /entrypoint.sh
    ENTRYPOINT [ "/entrypoint.sh" ]
    CMD [ "run_server", "-o", "option" ]
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.