Skip to content
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

When creating a stack, the env file is not found by absolute path. #4600

Closed
giomf opened this issue Dec 15, 2020 · 11 comments
Closed

When creating a stack, the env file is not found by absolute path. #4600

giomf opened this issue Dec 15, 2020 · 11 comments

Comments

@giomf
Copy link

giomf commented Dec 15, 2020

Bug description
When creating a stack, the env file is not found by absolute path.

Expected behavior
When I specify an Env file by absolute path, I expect the file to be read and the values to be set as environment variables in the container.

Portainer Logs

time="2020-12-15T18:51:44Z" level=error msg="Failed to parse service nextcloud-app: open /home/giom/repos/itmsio/nextcloud/secrets/nextcloud.env: no such file or directory"
time="2020-12-15T18:51:44Z" level=error msg="Could not parse config for project nextcloud : open /home/giom/repos/itmsio/nextcloud/secrets/nextcloud.env: no such file or directory"
2020/12/15 18:51:44 http error: open /home/giom/repos/itmsio/nextcloud/secrets/nextcloud.env: no such file or directory (err=open /home/giom/repos/itmsio/nextcloud/secrets/nextcloud.env: no such file or directory) (code=500)

Steps to reproduce the issue:
The following folder structure is on my server:
├── invoice
│ ├── docker-compose.yml
│ └── secrets
│ ├── database.env.dist
│ └── invoice.env.dist
├── nextcloud
├── docker-compose.yml
├── secrets
│ ├── database.env
│ ├── database.env.dist
│ ├── nextcloud.env
│ └── nextcloud.env.dist
└── volumes

A snippet of a docker-compose.yml file shows how I set my paths to the secrets but also to the volumes:

version: '2'

services:
  nextcloud-app:
    image: nextcloud:20.0
    container_name: 'nextcloud-app'
    env_file:
      - ${SERVICE_DIR}/secrets/nextcloud.env
    volumes:
      - /mnt/data/services/nextcloud/data:/var/www/html/data
      - ${SERVICE_DIR}/volumes/app/html:/var/www/html
    depends_on:
      - nextcloud-database
    networks:
      - nextcloud-net
    restart: unless-stopped

Now to start a stack, I copy the Docker-compse.yml file into the web editor of Portainer. Thereby I set the variable SERVICE_DIR to the corresponding folder by the options the UI gives me.

After clicking on "Deploy the Stack" a red pop up appears in the upper right corner which tells me that the path was not found. Exact wording: "Deployment error
open /home/giom/repos/itmsio/nextcloud/secrets/nextcloud.env: no such file or directory".

However, the path is correct. It should also be mentioned that this method works for volumes and that a start via the naked "docker-compse up" command also works.

Am I missing something here?

Technical details:

  • Portainer version: 2.0
  • Docker version (managed by Portainer): Docker version 19.03.13-ce, build 4484c46d9d
  • Platform (windows/linux): Linux
  • Browser: Mozilla Firefox 83.0
  • Command used to start Portainer:
    "docker-compose up -d" with following docker-compose.yml file:
version: '3'

networks:
  portainer-net:

services:
  portainer:
    image: portainer/portainer-ce:alpine
    container_name: portainer
    restart: unless-stopped
    networks: 
      - portainer-net
    ports:
      - 9000:9000
      - 8000:8000
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./volumes/portainer-alpine:/data
@crgrimwade
Copy link

Dont know if you got further with this but portainer is looking for that path inside its own container and not in the host system

@andylizi
Copy link

andylizi commented Mar 3, 2021

portainer is looking for that path inside its own container and not in the host system

The first thing I tried was placing the env file at the corresponding path inside the container, and it still didn't work, which was very weird.

Just tried it again and it works now. My bad.

@dnburgess
Copy link

You need to specifically mount the .env file in your stack, not just place it in a mounted volume.

@crgrimwade
Copy link

You need to specifically mount the .env file in your stack, not just place it in a mounted volume.

Do you mean mount into the portainer container - if so to where. I cannot find any documentation about this.

@giomf
Copy link
Author

giomf commented Mar 3, 2021

Dont know if you got further with this but portainer is looking for that path inside its own container and not in the host system

Thank you, I am now also aware of that. However, this seems to me to be very cumbersome. Since it has been tracked as a bug, it doesn't seem to be intended that way either.

@dnburgess
Copy link

Do you mean mount into the portainer container - if so to where. I cannot find any documentation about this.

You can find information about it here: https://docs.docker.com/compose/environment-variables/#the-env-file

Here is an example docker-compose.yml:

version: '3'
services:
  api:
    image: 'node:6-alpine'
    env_file:
     - ./Docker/api/api.env
    environment:
     - NODE_ENV=production

@deviantony
Copy link
Member

Could be related to #4813

@yannduran
Copy link

You need to specifically mount the .env file in your stack

How exactly do you do that? And have you confirmed your method works?

You can find information about it here: https://docs.docker.com/compose/environment-variables/#the-env-file

How does that help with the problem being experienced in Portainer? That information only seems to be pertinent to using docker-compose up manually.

In a stack, the .env file doesn't seem to be found no matter how you try to reference it.

@huib-portainer
Copy link
Contributor

@yannduran can you please try something similar to this example: #5199 (comment)
Note that there's a preview build as per #5199 (comment)

@connordeckers
Copy link

@yannduran I found that if I mount a directory into the portainer instance (ie. docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data -v /var/opt/mgmt:/var/opt/mgmt portainer/portainer-ce:2.9.0) then I can reference the env file from in there.

Note the -v /var/opt/mgmt:/var/opt/mgmt, meaning that I can reference files as such:

image

For context, I have them in the same location on my physical box, but mainly for my own piece of mind/previous implementations. YMMV :)

It took me ages of trial and error, but hopefully that'll help!

@huib-portainer
Copy link
Contributor

Closing as a duplicate of #6390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants