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

  • Difficulty accessing Docker's API
  • Docker how to map subdirectory to port
  • Mount specific EBS volume to Docker under AWS beanstalk
  • boot2docker access elasticsearch on localhost
  • How to retrieve metrics from Postfix in Docker Container
  • Docker forking process
  • 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 !!!

  • JHipster docker image from DockerHub is not working
  • Docker client cannot connect to daemon version 1.9: connection reset by peer
  • Shipping multi-container Docker app
  • Deploying ASP.NET 5 app to EC2 in a Docker container
  • Docker on Mac: No space left on device
  • How to execute commands in docker container as part of bash shell script
  • 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.