New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stack.env
does not work
#6701
Comments
same issue here |
Seeing the same behavior on EE 2.12.1 |
Ditto on EE 2.12.1, running on a swarm When I go into the portainer vol, the compose folder that it's looking for doesn't exist. If I create the stack and then add env_file to the compose, it's never created in the compose folder created for the id. If I create an empty file in that folder the stack is able to be updated with the env_file definition, but the file isn't updated with the env set in the gui. |
Only way I have been able to get this to work is by passing
|
Same issue for 2.13.1 on EE. I had to revert to specifying environment variables manually... If anyone needs to quickly generate required YAML, you can use the following. Switch to "Advanced Mode" copy everything into a file somewhere (i.e. /tmp/z). EXAMPLE
$ cat /tmp/z
VAR1="TEST"
VAR2="TEST" awk -F= 'BEGIN{print " environment: "}{print " "$1": \"${"$1"}\""}' /tmp/z Which should output environment:
VAR1: "${VAR1}"
VAR2: "${VAR2}" |
to me, the error reason was the path of docker-compose.yml(using git repository), seted on Compose path field Compose path: /some-project/docker-compose.yml Before: version: '3.4'
services:
some-project:
env_file:
- stack.env
build:
context: .
image: some-project
restart: always
ports:
- '8080:80' After(Working): version: '3.4'
services:
some-project:
env_file:
- ../stack.env
build:
context: .
image: some-project
restart: always
ports:
- '8080:80' Obs: I know it doesn't answer your question, but it could be related. |
My problem is that when you specify env_file: myvars.env The server works fine, but the |
Unfortunately, correct, I'm not specifying a local directory/project. Just letting Portainer manage everything (using its own volume) when I enter in the environment fields. Another solution was to manually add the "stack.env" file into Portainer's volume... which defeats the purpose of managing stacks through Portainer IMO. I see #6911 is related to this issue and looks like an internal ticket has been created? Hoping that's the case. |
I am also experiencing the same issue, referencing 'stack.env' as per the blog post results in an error:
EE 2.14.0, docker swarm mode. This is a bit confusing, as I'm fairly certain I am following the blog post instructions correctly. |
Blogpost has been updated to reflect that this currently only works for Docker Standalone and not for Docker Swarm. |
@samdulam It also doesnt work for portainer agents, only the server. |
I wanted to follow up on this request. I created a New Environment >> Docker Standalone >> Agent >> Create Stack >> Docker Compose >> Load Thanks! |
Tried using local (docker.sock) environment and Portainer agent environment. Both give errors saying With portainer agent, it worked after trying the suggestion from JuniorC07. changing the path of |
Hello, just a couple more, hopefully useful, use cases :) Using "stack.env" does not currently work when:
It does work, however, by using "../stack.env" as path instead. Using "stack.env" on the other hand, works just fine when:
|
Thank you for the additional information. I am going to further investigate the Thanks! |
Is this what you are trying to do here: Thanks! |
Hey, just wanted to say that I have the same problem. I'm deploying a docker-compose.yml file that sits in a subdirectory of a git repo. Trying to use stack.env as the env_file doesn't work but ../stack.env does PS: I'm using Portainer BE 2.16.1 |
@tamarahenson the idea is to do: where the docker-compose.yaml referenced is:
which should work according to https://www.portainer.io/blog/using-env-files-in-stacks-with-portainer but results in error: If I put "- ../stack.env" as the env_file in the compose.yaml, instead, it works, I guess because the stack.env file is generated as /data/compose/stack.env. Interestingly, if I just use the same docker-compose.yaml directly in portainer (with Web Editor) it instead works with "- stack.env" as expected. |
Here is my testing. I am unable to reproduce in Portainer CE or BE: Screen.Recording.2022-11-18.at.2.09.33.PM.movThis is my
This is my My mistake earlier was trying to call the Thanks! |
Hi again @tamarahenson, I'm not trying to reference an existing "stack.env" inside the git repository. In fact I absolutely do not want an .env file in the git repository since it contains secrets. The idea is to do as documented in https://www.portainer.io/blog/using-env-files-in-stacks-with-portainer This indeed works with Web editor in Docker Standalone, but not in "Repository" mode where you need to use "../stack.env" instead. Hopefully this is more clear, thank you for your time :) |
Thank you for the additional information. I figured out how to reproduce this. [1] I changed the name of my TODO: Update our Blog with further instructions for Git Repositories Thanks! |
I am experiencing the exact opposite on Portainer 2.16.2, Docker Standalone environment connected through
This thread and the documentation could really use some clarification on this. |
Same issue here. |
I just encountered the exact same conditions here. The stack won't deployed (the stack.env not found) when I enabled the relative path volumes. |
It's a bit disappointing to see this issue still being open. I am happy to provide a reproduction if needed but this is a long-term dealbreaker for us. Can anyone of Portainer Crew please comment why this is not worked on? Stacks are not unimportant... |
Can you give details of the stack? Include screenshots of the repo folder structure along with Stack config screen in Portainer. Also don't forget to mention the platform details: Docker Standalone / Swarm, OS and CPU Architecture. |
On my end this is easily reproduced using the following: Docker Standalone, using a server & a couple agents Brand new repo with only Full portainer config screen: https://github.com/portainer/portainer/assets/81395386/8dc12d24-f044-4a28-972f-103194877433
The error: https://github.com/portainer/portainer/assets/81395386/10d641c4-414a-47f1-8554-d667eba3e2e9 Either removing the I tried rolling back the versions to test but it resulted in some instability. I haven't had time to spin up fresh environments to play with and see if I can figure out when it broke. |
When was the
|
@UrsaSolar |
@darioackermann Do you also reference |
Maybe because the documentation states that this file is generated by portainer when deploying a stack ? |
@Geekimo |
@samdulam https://docs.portainer.io/user/docker/stacks/add#:~:text=Alternatively%2C%20on%20Docker%20Standalone%20environments%20you%20can%20add%20stack.env%20as%20an%20env_file%20definition%20to%20add%20all%20the%20environment%20variables%20that%20you%20have%20defined%20individually%20as%20well%20as%20those%20included%20in%20an%20uploaded%20.env%20file%3A |
I can see the problem. This is not the case when deploying from Git, if you refer to We should however clarify this in the documentation. |
We had an empty
I see the point and I generally agree it makes sense, but I'd consider it an awesome feature to enable this for git-deployed stacks as well - such that exposing credentials on git is not necessary. |
@darioackermann |
Hi guys, I am having the same issue. But I am not deploying from repository. Am I right that I should be able to :
Am I doing something wrong ? Thanks a lot |
should work for docker but won't work for docker swarm. |
Oh right, so that is my problem. Don't think it's well documented. So with Docker Swarm, the only way to use environment variable editor from Portainer, is to add all env vars to editor, and then use them in docker-compose.yaml with $ ? Thanks, it seems it is clear in comments : https://www.portainer.io/blog/using-env-files-in-stacks-with-portainer |
We add service-that-needs-aws-creds:
image: xyz.dkr.ecr.eu-central-1.amazonaws.com/xyz
build: ./services/xyz/ # for docker-compose build
environment:
- CUSTOM_ON_404=index.html
- ....
env_file:
# Secrets in Portainer
- stack.env
restart: unless-stopped This seems to be working with relative paths off and after recreating the stack from scratch. |
I was following this Portainer blog post, which is the only thing I could find when searching for anything regarding Portainer and variables. I ultimately want to keep secrets out of the git repo.
I've moved to using variable substitution in most the affected stacks to get it working again. At first I wasn't aware of individual variable substitution, as the above post gave the impression that Portainer only supported adding all or nothing when it came to variables. In fact, I don't even remember where I leaned about variable substitution now, I can't find anything in the docs after a quick skim. My expectation was that it would be able to both clone the repo and create Personally I think variable substitution is a better solution for what I'm doing anyways, so my ultimate opinion is that this is really a documentation and UI issue. I was originally uncomfortable with the fact that everything had to get all the variables, but didn't deem it a dealbreaker. Substitution is much better for me. But I wanted to report the breakage all the same. |
The solution I'm using is to consume the portainer API directly from the pipeline of a git repository. So to create a stack I place the environment variables as secrets variables (Gitlab>Conf>CI/CD>secrets) in the repository, this allows me to obfuscate their call during execution. And then I add them as complementary variables via payload using the parameters below. "env": [ And then in docker-compose.yml: This was the only way to do GitOps using Git+Portainer+Swarm. I think that the passage of variables could be better adapted by the portainer team. this is an important feature |
Thank you! I didn't even think about the fact that portainer itself is a container and the fact that by default it might assume the pathing provided in env_file is a portainer container path and not a host path. I added /nfs/configs:/nfs/configs:ro as one of my portainer bind mounts and then immediately all of my .env files starting with /nfs/configs pathing were found. |
It seems the issue is caused by the env file not being generated (or accessible) across nodes in a swarm. I ended up manually putting the stack.env onto the portainer data volume, into the appropriate compose folder. |
Seems like a bug. Trying to deploy on CE v2.19.4, and the Stack YAML editor says |
Same issue... I also use a swarm setup. |
@christianstrauch, @ecker00 and @voslucas : Did you tried this? #6701 (comment) Portainer itself is running as a docker service, which means that you need to add volumes that matches the host path. Otherwise portainer can not "see" the files 🙂 |
Same issue with me. I spend the whole day yesterday trying to fix this. Issue remains with no proper solution |
Hello there, I experienced the same situation and expent a lot of time investigating, turns out that I was referencing an .env file in the code as overlooked it. This is not needed as you can import the variables in the new stack interface from a file and it will define all the values in the env files making it unneeded to specify the env file in the new stack code. If you really need to put the env file in the new stack code, you can also take note of the missing file error, and recreate the path adding +1 to the path in the portainer container files. I hope this helps you guys out there! |
"you can also take note of the missing file error, and recreate the path adding +1 to the path in the portainer container files" what do you mean add +1, can you give an example? |
Yes and sorry for not including it originally. When a new stack is deployed, it gives a number to the path:
So I noticed that if you wish to redeploy it with the env file on the server, you need to place the env file under the next one:
I hope this helps |
Bug description
Following along with the tutorial here: https://www.portainer.io/blog/using-env-files-in-stacks-with-portainer I get
stack.env: no such file or directory
Expected behavior
stack.env
should work as per the above blog post.Portainer Logs
Steps to reproduce the issue:
Be running in swarm mode.
Create a new stack with the content.
Add at least one environment variable to the environment variables section.
Try to deploy.
Technical details:
docker run -p 9443:9443 portainer/portainer
): Uhh, it's been running for a while as a stack...Additional context
Assessing the possibility of running a dockerized mail server through portainer for my employer.
The text was updated successfully, but these errors were encountered: