coolify
coolify copied to clipboard
[Bug]: Docker deployment not considering environment variables
Description
I was using Dockerfile and Docker based deployment for one project. It worked properly as I expected when I first tried. Not exactly sure what happened, when I try the same thing after 2 days, it is failing health checks. I checked and it is failing to get the environment variables. Not sure what happened or if I m doing something. Please let me know if I m doing something wrong here. Quick response is appreciated. Thanks.
Minimal Reproduction (if possible, example repository)
- Add some environment variables in Coolify dashboard.
- Use a Dockerfile to deploy an app which uses these environment variables.
- Try to see if the deployment's health status becomes healthy and accesses the variables properly.
Exception or Error
Health check of the deployment is failed.
Version
v4.0.0-beta.271
I'm also having problems with environment variables, but I'm using docker-compose. In my application the variables appear, but without value. The ${KEY} variables are not being replaced by the values defined in Coolify.
@vchiranjeeviakt could this be related to #2073 ? have you tried logging the env vars ?
This is not about wrong health check @fcpauldiaz . Health check is working fine and failing because app is failing to start due to no environment variables. I tried to run the image created by coolify manually and it is throwing proper env not found error. I tried to echo a variable in pre-deployment command. From whatever I understood of pre-deployment command, it should print that value, correct me if I m wrong. But, didn't print anything in deployment logs.
Please confirm that adding env variables in dashboard should make them available for docker container right?
Also, I m using coolify cloud if that makes it any clear.
@vchiranjeeviakt got it, I'm not a maintainer but in my experience when updating an env var, it is better to try a deploy without cache, maybe that could help.
Yes @fcpauldiaz , I deployed without cache, I have deleted the environment and recreated new one as well. No luck. There is a version update, I will try again once.
Hey, same situation here!
Environment variables are not passed to the Dockerfile used by my Coolify resource. There's nothing in the doc related to this exact situation, everything seems to refer to the docker-compose.yaml deploy method
I am still having the same issue. Somehow, the environment variables are not being picked up. Maybe I am looking in the wrong spot, but I am running env in the Execute Command section to see the environment variables and there the ones from the project are not listed. But maybe they shouldn't be?
Same issue here.
I entered every and all env variables properly for my preview deployments, and it fails to pass it towards the containers.
There are several issues mentioned in this, so let me answer them:
Healthcheck fails on Dockerfile deployments
There was a change in the healthcheck process. Before it was always healthy, but since the previous few versions, it is checked properly.
This means you need to have curl or wget installed inside the Docker image, otherwise Coolify cannot check anything.
If this is not a solution for your use-case, turn off the healthcheck.
Build env variables are not shown during build-time
Do not forget to add them as ARG BUILDENV in your Dockerfile. More details here.
Pre commands
It has been fixed since then. It should work now.
@andrasbacsai ; I'm not sure my issue is related.
I'm failing to pass preview env variables to a docker-compose project.
It works perfectly fine for raw env variables but never passes properly to preview ones.
I'm using Coolify Cloud and all the latest updates.
I've tried:
- Duplicated env variables in
args,environmentto ensure they are present - Rebuilding all my containers, it always work properly in base deployment, never passes in preview
- Moving ARG in all steps of my image build
- Rewriting every env variables by hand instead of developer view
- Enabling/disabling "build variable" and all other settings and redeploying
Ah, preview deployments. I can reproduce that one - will fix it.
Thank you so much for quick response @andrasbacsai ; loving Coolify here! :)
Can we please reopen this issue? Im on beta 306 and i still (or maybe again) having the issue that in my preview build none of my preview or normal environment variables are considered.
I have the same issue as @knurzl on beta.306. I have several environment variables defined but my docker container is not able to access them. @andrasbacsai can we please re-open this issue?
Can confirm same issue again with beta 306 also on my end. Also seeing strange behavior with $ signs in the env values
The dollar sign is a special character to reference other variables. If you want to use it literal you have to check the box "is literal".
Can confirm same issue again with beta 306 also on my end. Also seeing strange behavior with $ signs in the env values
The dollar sign is a special character to reference other variables. If you want to use it literal you have to check the box "is literal".
Yes indeed got everything working. please ignore my comment from above 👍
I'm running into this issue as well. A build-time environment variable works perfectly for regular deployments but seems to be missing during preview deployments. Using version beta 315.
I can't seem to get build variables to work with Compose.
I have these two files:
# docker-compose.yml
services:
app:
build:
dockerfile: Dockerfile
# Dockerfile
FROM alpine:latest
ARG test_secret
RUN echo ${test_secret} > /test_secret_file
ENTRYPOINT ["tail", "-f", "/dev/null"]
I add test_secret variable in "Environment Variables" and check "Build Variable?".
Deployment results in test_secret_file being empty when using "Docker Compose" Build Pack, but with "Dockerfile" Build Pack, the file contains the value.