docker-compose


docker compose environment variable for command


I am having troubles in passing environment variables to my custom image via the compose command option:
My compose file:
---
version: '2'
services:
myservice:
image: mycustomimage_lms
environment:
CONF_HOME: /opt/apps-java/
APP_ENV: dev
UUID: me1
command: -Dconfig.home=${CONF_HOME} -Dcomponent.name=LMS -Denv=${APP_ENV} -Duser.dir=/tmp/ -DLMS_UUID=${UUID} -jar /opt/apps-java/my.jar
ports:
- "9060"
volumes:
- ./:/opt/apps-java/
- ./:/var/logs/apps-logs/
- ./:/tmp/data
My image is just a custom jre image which has an entrypoint set to a shell script that accepts jvm arguments. My run.sh that is called from enrtypoint
#!/bin/sh
export JAVA_HOME="/usr/java/latest/"
exec $JAVA_HOME/bin/java $#
I need to pass values to command at runtime since I can then use my image for a lot of other jars and just changing parameters to my image.
This is what i get:
$> docker-compose up
WARNING: The CONF_HOME variable is not set. Defaulting to a blank string.
WARNING: The APP_ENV variable is not set. Defaulting to a blank string.
WARNING: The UUID variable is not set. Defaulting to a blank string.
I have also
gone through couple of answers such as :
Docker Compose - Command using Container Environment Variable
and
Docker-compose environment variables
but could not get it working. Any directions please?
The variables are being read by Compose when the file is parsed. But setting environment only provides values to the container, not to the file parsing.
If you're trying to pass those variables into the container, you need to escape them in the command using an extar $
-Dconfig.home=$${CONF_HOME} -Dcomponent.name=LMS -Denv=$${APP_ENV} -Duser.dir=/tmp/ -DLMS_UUID=$${UUID
If you're just trying to use variables in the Compose file, you need to put those variables into an .env file.
See https://docs.docker.com/compose/environment-variables/ for the full documentation

Related Links

Docker compose file config
Systemd “No such file or directory” itself during “docker-compose up”
Docker compose yml static IP addressing
compose extend file results in a validation error
hubot rocketchat adapter does not work
Docker compose lables constraint:node not work
is it possible to generate a random mysql password with dockercompose
Networking Docker Compose
How to change the config file for Riak TS when using Docker
Django Docker-compose machine does not start web server
How should docker-compose jobs discover etcd?
docker compose adding nodes dynamically to nginx frontend
Docker Swarm - dependencies definition
docker-compose volume not mounted
Exposing sentry service in docker-compose file
Yesod and docker-compose logs in development mode

Categories

HOME
airflow
joomla
gcc
salesforce
gap-system
skypedeveloper
pandoc
snmp
grid
flowtype
annyang
runtime
websharper
yui
react-select
internet-explorer-7
md2
loader
passbook
sonarlint
ampscript
connectiq
tcpdf
email-client
bootstrap-accordion
rancher
smart-device
scripting-language
boosting
launchd
windows-10-mobile
federated
apm
vtd-xml
wordpress-rest-api
log4net-configuration
postgresql-9.6
android-scrollview
webspeech-api
voyager
traitsui
outlook-2010
linkurious
jvisualvm
autodesk-data-management
contenteditable
spring-data-commons
yank
import.io
visio-2010
sp
android-vectordrawable
selection-sort
totalview
blackberry
overhead
catalyst
android-music-player
firebase-polymer
boost-range
xcode7.1
scriptengine
git-cherry-pick
audiorecord
python-rq
factorization
kramdown
consul-template
cakephp-2.6
jeet-grid
beagleboard
xmlserializer
nsnotificationcenter
sat4j
time-frequency
rails-migrations
sigma-grid-control
image-preloader
nodeunit
grunt-contrib-imagemin
mobile-robots
xrandr
backbone-views
nsautoreleasepool
database-restore
rfc822
report-viewer2010
netbiscuits
shapado
ios6-maps
jqueryi-ui-buttonset
excellibrary
text-manipulation
helios
file-storage
coderush-xpress
stackless

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App