I have an application that on play that use aerospike
in application.conf i have a param that i can rewrite from environments
aerospike.hosts = ["192.168.33.10"]
aerospike.hosts = ${?DS_AEROSPIKE_HOSTS}
how i can set list of hosts in my docker compose file?
version: '3.1'
services:
ds-aerospike-db:
image: aerospike/aerospike-server
restart: always
volumes:
- volume:/opt/aerospike/etc
command: ["--config-file","/opt/aerospike/etc/aerospike.conf"]
ports:
- 3000:3000
dashboard:
image: dashboard:0.1
restart: always
ports:
- 9000:9000
environment:
DS_AEROSPIKE_HOSTS: '["192.168.33.10"]'
this format is an error DS_AEROSPIKE_HOSTS: '["192.168.33.10"]'
I believe you can't pass an array to the ENV variable.
But you can pass it as a string, and then, later, parse string at your application.
environment:
- DS_AEROSPIKE_HOSTS='192.168.33.10,192.168.33.11'
the valid docker-compose.yml syntax is stated at docs
https://docs.docker.com/compose/environment-variables/
I'm not familiar with scala, but I believe you can do something like
aerospike.hosts = ${?DS_AEROSPIKE_HOSTS}.split(',')
You have a couple of options:
You can include a docker.conf file in your Docker build and inject the settings you want into that file. Then you can include the docker.conf file from your application.conf. E.g. add this to your application.conf:
include "docker.conf"
You can use an environment varible to pass a string value (as suggested by Stanislav) but then convert it to a sequence. The idiomatic way to do this is to make a ConfigLoader and then use it to convert a String to a Seq[String]. E.g. something like:
implicit val stringSeqLoader: ConfigLoader[Seq[String]] =
ConfigLoader(_.getString).map(_.split(','))
Related
I'm creating test.conf configuration file by using a python script which will be volume mounted to docker-compose.
In python script there are few configuration variable, for which I need to check the values in container and accordingly generate the config.
Python snippet to generate the config file :
dns_ip = os.popen('cat /etc/resolv.conf').read()
dns_match = re.search(r'(\d+\.\d+\.\d+\.\d+)',dns_ip)
try:
if match:
dns = dns_match.group(1)
service_config.append('add service dns_service '+dns+' DNS 53 -healthmonitor NO')
service_config.append (.....
.......
#### Creating config file ######
f = open('test.conf','w')
for i in service_config :
f.write(str(i)+"\n")
docker-compose file where generated test.conf from above python script will be volume mount:
test-docker:
image: test
network_mode: bridge
ports:
- '444:8443'
privileged: yes
ulimits:
core: -1
volumes:
- /test.conf:/config/test.conf
Please suggest that how such configuration can be applied after checking the values in container ? Can I pass these details as environment variable, if yes, then how can I achieve it ?
We have a docker-compose.yaml file in which a parameter APP_DEBUG from .env.local, which sets if xdebug is active or not:
php-fpm:
build:
context: .
dockerfile: ./docker/php-fpm/Dockerfile
args:
- TIMEZONE=Europe/Berlin
- WITH_XDEBUG=${APP_DEBUG}
container_name: ${PROJECT_NAME}-php-fpm
environment:
XDEBUG_CONFIG: "remote_host=docker.for.mac.localhost remote_connect_back=0 remote_enable=1 remote_autostart=1 remote_port=9009"
PHP_IDE_CONFIG: "serverName=docker-server"
working_dir: /var/www
volumes:
- .:/var/www:cached
ports:
- ${HOST_WEB_PORT}:80
If I have my container up and running and want to switch xdebug or or off, is "stop" and "start" enough for the container to react to the change or do I need to do "down" and "up" or even a new build?
Build config options are applied at build time. So, think you are going to need to build your image and run the container again.
Source Build docs
I noticed that the docker-compose.yml file of a project contains syntax such as &id001 and *id001, &id002 and *id002 in various services. For example:
version: '2.3'
services:
nlp-servlet:
...some configs ...
logging: &id001
driver: json-file
options:
max-file: '10'
max-size: 10m
consul:
... some config ...
logging: *id001
redir:
... some config ...
volumes:
- redir_log:/usr/src/app/log
logging: *id001
tbgas-db:
... some config ...
volumes:
- tbgas_db:/var/lib/mysql
logging: *id001
volumes:
logdir: &id002
driver: local
redir_log: *id002
tbgas_db: *id002
I can kind of guess how id001 and id002 work, and I think they work a bit differently. Is that accurate?
Also, where can I find some documentation about this type of syntax? What are they called?
These are YAML anchors: the & declares it as an anchor, and the * references it, being replaced by the actual contents in the anchor. You can see more examples of its usage in this section of the compose file reference.
I would consider moving these into extension fields if possible, and giving them descriptive names to avoid confusion.
I plan to add meta information in my docker-compose files, but I don't know if it's possible/a good way.
Figure this service, and the meta key:
OldMongoDB:
image: mongo:3.2
environment:
- URL: mongodb://localhost:27015
ports:
- "27015:27017"
meta:
- meta1: "some value usefull in tests"
- meta2: "other value usefull in tests"
Is it good for you to store additional values inside a docker-compose?
This is to be used by test scripts.
I am trying to build a Stack as follows:
redis:
image: redis
ports:
- '6379'
app:
build: .
links:
- redis
when I push "Create Stack" button, I get this error:
Oops!
Service 'app': Value {u'build': u'.', u'links': [u'redis'], u'name': u'app'} for field '<obj>' contains additional property 'build' not defined by 'properties' or 'patternProperties' and additionalProperties is False. See 'https://support.tutum.co/support/solutions/articles/5000583471' for more details
Can someone help me with this please?
The Tutum documentation states the following at the bottom of the page:
Docker-compose non-supported keys
Tutum.yml has been designed with docker-compose.yml in mind to maximize compatibility, but the following keys are not supported:
build
external_links
env_file
This clearly states that build is not a supported key, which is what your error message also says. It looks like you'll have to remove the build key from your file.