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 - image not found
How to work out the hostname that compose gives containers?
docker-compose restart container if service is dead
Swarm scheduling not working as expected using filters in compose file
issues in buiding Slate with Docker
Invalid type error in Docker Compose
Django cookiecutter with Docker add pip package
Docker Compose + Swarm + Machine Networking issue
docker-compose build image parameters --force-rm --pull
linking 2 containers through docker compose
Files created by manage.py commands not chown'd from root user
Is it possible to create an intermediate image within docker-compose?
docker-compose service listen on specified interface
Does Docker-Compose allow overwriting of ports when using extends?
Jhipster Docker-compose conflict
Build multiple images with Docker Compose?

Categories

HOME
javafx
indexing
stata
marie
sql-server-2014
domain-driven-design
salesforce
readdir
opc-ua
ethereum
velocity
android-notifications
computation-theory
restructuredtext
fastboot
apdu
android-wear-2.0
deployment-descriptor
sasl
windows-mobile
cloudformation
meteor-accounts
emr
csproj
r-factor
textview
qt-designer
n1ql
http-proxy
ansible-inventory
maven-2
abide
oracle-bpm-suite
const
server-side-swift
azure-web-roles
file-descriptor
java-5
flume-ng
intervention
piranha-cms
ocpjp
xmldom
rivets.js
multivalue
playframework-1.x
sharpssh
seyren
boost-regex
robotc
recursive-query
fileopendialog
firebase-polymer
papyrus
gdi
diameter-protocol
system-integration
treelist
code-translation
music-player
kramdown
random-sample
persian
traminer
borland-c++
tokudb
fileinputstream
cordova-3
mind-manager
qf-test
os.walk
register-allocation
sync
redmine-plugins
twitter-finagle
rda
rssi
power-management
8-puzzle
myrrix
oc4j
playing-cards
usersettings
dynamic-expresso
cocotron
msbuild-task
zepto
moonscript
m3u
derived-class
states
animationdrawable
datejs
visual-leak-detector
mscorlib
session-hijacking
vectorwise
sipdroid
auto-compile
n2
marathontesting
database-agnostic
jquery-attributes
large-data-volumes
djangoappengine
file-icons
content-delivery-network
software-update
scalable

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