I am encountering an issue with my Docker-compose setup where one of the services, specifically the profiles service, keeps restarting continuously. I’m seeing warnings in the logs related to unset variables, but I’m not sure if they are the root cause of the problem. Here’s an overview of my docker-compose.yml configuration:
The postgres service seems to be running fine, but profiles keeps restarting.
The logs show warnings about unset variables like "o58":
PS C:\Users\admin\profile> docker-compose logs --tail 50 --follow profiles
time="2024-02-25T12:17:28+02:00" level=warning msg="The \"o58\" variable is not set. Defaulting to a blank string."
time="2024-02-25T12:17:28+02:00" level=warning msg="The \"o58\" variable is not set. Defaulting to a blank string."
time="2024-02-25T12:17:28+02:00" level=warning msg="The \"o58\" variable is not set. Defaulting to a blank string."
PS C:\Users\admin\profile>
I think that the problem is not from these logs.
Could someone please assist me in troubleshooting this issue? Any insights or suggestions would be greatly appreciated.
It is very urgent task! I MUST be ready by the end of the day.
Why do you think it is not related to the warnings? Do you recognize the variable name? For me it doesn’t look like a variable name. And it is exactly what Docker Compose shows when you have an unset variable. I don’t remember seeing it in a container log.
If the container restarts, then the aplication fails inside the container. If it doesn’t log the reason, it is hard to say anything unfortunately, but the undefined variable is something I wouldn’t ignore.
Actually, the only place where I found something like o58 is here: .env: SECRET_KEY=22+sg%5+##a=^-$o58(1q9(^r@cjl-p0r3m^x9@-#i=1qcs2y12asdwqz2341casdf%zx When I remove the $ sign before o58, the log disappear, but it keeps restarting (not running).
You didn’t share the real secret with us, did you?
When variables are used in compose, every $ character needs to be escaped with another $ character. I am not sure if this still applies if the value is taken from an .env file, but it could be very much the case.
If possible I would recommend testing with a SECRET_KEY without special characters and isolate if the special characters are the problem.
Furthermore, you will want to add additional debug output to your entrypoint script and/or application, to get an idea of where and why exactly something is not working.
As @meyay wrote, you need to escape the dollar characters. You can do it by adding a second dollar character or just using apostrophes around the value like you would in a shell script
SECRET='secret$abc'
This works only i you want to escape all the dollar characters and don’t want to use any variable in the value. Otherwise the double dollars are what you need.
Since you already had an incorrect variable definition, it could be already saved in a database or in a cache file, so I would recommend removing everything and starting from scratch.
Again, without error messages, there is not much we can say. If the password was not the only problem, and you have no error messages, then it is now about application debugging and we don’t know that application, only you.
One important thing which is related to Docker: You always need to run a process in the foreground in the container to keep it alive. If you don’t have that, then your container will just stop without error messages.
You can share the Dockerfile, which could contain the command and entrypoints. If you have a command or entrypoint script, you can share that too. The rest of the application can be useful too, but unless the error is obvious, I don’t think I will recognize the problem.
It would be better if you could share it as a code block directly in your message. If the application has too many files or too long source code, I won’t have time to check it anyway. So let’s start with the Dockerfile and optionally with the application. Maybe you can share the entrypoint of the application source code as well, like a main file or main method but not all of it.
You do understand that you are the only one that has the full context information, and you share them one by one. If you want us to help efficiently you need to start sharing enough context information so we understand what you try to achieve, what you did and how you did it.
Please make the answer to “what does someone who doesn’t know the context need to know to understand what I am responding?” part of all your posts.
We know the mechanics of docker, but you must provide the details of your programming language and your application needs.