Pass parameter (like -Des.node.name=“TestNode”) in docker run from Ansible or Fig
I need to use dockerized Elasticsearch from dockerhub official image and launch docker container using Fig or Ansible. Both have options for passing standard docker run command params like ports, volume etc, but I could not find a way to pass params like
-Des.node.name="TestNode" to configure the Elasticsearch cluster name etc.
I cannot modify Dockerfile to alter config as these are runtime config and differ among installation, hence need to pass at runtime.
Do anyone have any idea how to use Fig or Ansible to pass such params.
2 Solutions collect form web for “Pass parameter (like -Des.node.name=“TestNode”) in docker run from Ansible or Fig”
Fig has been replaced by
docker compose for quite some time now.
And the way to pass such parameter is:
- using runtime environment variables which will be visible by the container run after
docker compose up,
- having a starting script in
CMDwhich will expect and use those environment variables in order to build the right command starting ElsticSearch (with
As -D is specific to Java (JAVA_OPTS) and not as ENV or docker params, this can be passed with JAVA_OPTS environment variable. Like:
sudo docker run -e JAVA_OPTS=-Des.script.groovy.sandbox.enabled=true -p 9200:9200 elasticsearch:1.7.1
Now Fig or Ansible can pass ENV variable JAVA_OPTS. Only catch is to ensure original JAVA_OPTS is preserved.