Variable substitutions in docker-compose in Azure Docker Web app - azure

I have a docker-compose file that contains a secret for my database.
port: 4466
managementApiSecret: ${DB_SECRET}
So I would like to use Docker-Compose's Variable Substitution (https://docs.docker.com/compose/compose-file/#variable-substitution) to be able to provide my secrets through an environment variable instead of my yaml file.
Is this at all possible using the "Application Settings" variables on my Azure Linux Docker Instance?
It doesn't seem to work for me, I've tried both ${VAR} and $VAR syntax and neither worked. I also tried with secrets that only contain alphanumerics and numbers.
Thanks in advance.
Frank

Environment variables that you need to start the container (for example: you want to include build number in container name) can be added to .env file in same directory as the docker-compose.yml file.
sample .env file:
DB_SECRET=foo
run: docker-compose config and verify that the variable has been substituted with the value you have in .env file
Also, I recommend using managementApiSecret:"${DB_SECRET}" (note the quotes around the variable) in your docker-compose.yml file
There might be azure specific way to share secrets but I didn't try that yet.
If you want to pass in environment variables that the container needs, then https://docs.docker.com/compose/compose-file/#env_file is what you want. Those environment vars will become part of environment inside docker container.

Related

Using dotenv in cloud run

I have created a .env file in my local system while developing a project. If I upload my project along with .env file, will it work fine or do i have to assign env variables separately?
According to the documentation it won't work like that.
You can set them in Console or provide with --set-env-vars flags during deployment from command line or set id Dockerfile with ENV parameter.

How to read contents from Dockerfile in azure-pipeline.yaml file?

I have environment variable set in Dockerfile which is in Azure Repos part of the project. I have to set up Docker based pipeline in Azure Pipeline. I'm trying to get the environment variable content in azure-pipelines.yaml file.
Is it possible to access Dockerfile contents in azure-pipelines.yaml file?
Can we pass argument value (Environment value) to azure-pipelines.yaml file?
Please guide!
If you want to use an environment variable both when building your docker image and elsewhere in the pipeline, I'd suggest restructuring:
add a build variable to your pipeline, defining your environment variable; this will make it accessible to every task in your pipeline
remove the environment variable from the dockerfile
replace it with an ARG value, so your docker build step can pass in a --build-arg parameter, specifying the build variable

Setting environmental variables for node from host machine for build server

I'm using bitbucket pipelines as a build server.
I need to pass environmental variables from a host machine into a .env file which will then set the var values to be used in the build.
For example, lets say an environmental variable in a docker container running the build is AWS_ACCESS_KEY_ID.
In my .env file I'd like something like the following:
ACCESS_KEY=${AWS_ACCESS_KEY_ID}
I would then run the build and the ACCESS_KEY var would have a value equal to the env var in the docker container.
My current idea for a solution right now involves replacing values with sed, but that feels pretty hacky. Example:
.env file contains the following line:
ACCESS_KEY=<_access_key_replace_me_>
sed "s/<_access_key_replace_me_>/${AWS_ACCESS_KEY_ID}/g" .env
Any better solution than this?

How can I get the environment variable from docker file

How can I get the environment variable from docker file for example I am adding a
ENV URL_PATH="google.com"
in my dockerfile, so can I get the this URL_PATH in my Jmeter.jmx file with the help of User Defined Variable.
On window its working fine with proper {__env(URL_PATH)}
but on docker its not working. How can I solve this problem?
You can use the -e option to pass environment variables into the container when running it.
docker run -e URL_PATH=google.com ...
Docs: https://docs.docker.com/engine/reference/run/#env-environment-variables
As far as I can see __env() is a Custom JMeter Function therefore it is not available in vanilla JMeter so the options are in:
Amend your Dockerfile to include downloading of http://repo1.maven.org/maven2/kg/apc/jmeter-plugins-functions/2.0/jmeter-plugins-functions-2.0.jar to "lib/ext". This way you will be able to use __env() function in Docker environment normally. See Make Use of Docker with JMeter - Learn How for example Docker configuration assuming using JMeter with Plugins.
Switch to __groovy() function. Replace all the occurrences of {__env(URL_PATH)} with the following expression:
${__groovy(System.getenv('URL_PATH'),)}

Run JHipster in Docker with JHipster Registry-pass the variable ${jhipster.registry.password}

I am running JHipster application in Docker with JHipster Registry
how to pass the variable ${jhipster.registry.password} to app.yml
May I ask how to pass the variable ${jhipster.registry.password} to app.yml?
-
EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/config
That value is parsed from your application's bootstrap.yml (or bootstrap-prod.yml in prod) found in src/resources/config.
Another way to set this variable is to set the JHIPSTER_REGISTRY_PASSWORD environment variable in your docker-compose app.yml file

Resources