When creating a stack, support relative paths for volumes when using a git repository #9795
Replies: 40 comments 2 replies
-
I created a dirty workaround: ln -s /var/lib/docker/volumes/portainer_data/_data /data so that the path |
Beta Was this translation helpful? Give feedback.
-
Not a perfect solution, but I'm currently working around this using a temporary service container to checkout our Git files and then mount to the target container. Roughly something like: version: '2'
services:
# Service container
# Purge any leftover files, clone repo, copy necessary files to the temporary volume
# Note: you could also use a sparse checkout for this (size of clone, performance), but I didn't since my use case was pretty small
git-checkout:
image: bitnami/git:latest
working_dir: /temp
command: >
bash -c "
find /temp -mindepth 1 -delete &&
find /files -mindepth 1 -delete &&
git clone https://${GITHUB_TOKEN}@github.com/<username>/<repo>.git &&
cp -R ./<repo>/<directory>/. /<volume_location>
"
volumes:
- service_files:/<volume_location>
# Target container -> mounts files
target-container:
image: <image>
volumes:
- service_files:<target_directory_for_files>
volumes:
service_files: |
Beta Was this translation helpful? Give feedback.
-
I've been testing Portainer to see how well it might work for me and just ran into this issue. Here's my thought on what a solution might look like: Inspect the portainer container, find the /data mount, find what directory the current stack is checked out into, and then replace any relative paths on the stack's docker-compose with the full path from the host? Or if it's too much hassle to edit the docker-compose file before running it, set a variable that can easily be replaced, then ask users to put that in in place of the relative path. Anyway, just a thought I hope can start some brainstorming. :) |
Beta Was this translation helpful? Give feedback.
-
I hit the same issue. Here is my workaround. Pretty much what @jerrac suggests using env. The portainer config is pretty straight forward:
Add new stack from private git repository.
This will fail because But you can go into the Container -> Container details -> Labels Get this value and set the Ex. Also docker-compose has default value |
Beta Was this translation helpful? Give feedback.
-
We are also interested in this issue getting a proper solution. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I'm trying the When i configure an edge_agent portainer show me the command to run on the edge (I run the following in another device):
As you can see, unfortunately the agent version 2.17.0 is not avilabe on dockerhub, so i switch to the However, I've tried setting up a stack from a git repo, but the option enable relative path volumens is not present. |
Beta Was this translation helpful? Give feedback.
-
Any news on this for the ce edition? |
Beta Was this translation helpful? Give feedback.
-
When will this be launched as non-dev build? |
Beta Was this translation helpful? Give feedback.
-
It will be in the Business Edition 2.17.0 release. |
Beta Was this translation helpful? Give feedback.
-
Any estimate on a date for this release? Or a stable development build? |
Beta Was this translation helpful? Give feedback.
-
We're expecting to release that one early Feb. |
Beta Was this translation helpful? Give feedback.
-
@huib-portainer does it mean it will be a BE only feature ? |
Beta Was this translation helpful? Give feedback.
-
Given the following Tree layout |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Couple of things i discovered so far : you can specify path like this :
Where the
And right now, not sure if it's a bug, If i attempt to mount a non existent path, it will create a directory relative to the |
Beta Was this translation helpful? Give feedback.
-
oh awesome, I didn't know that the |
Beta Was this translation helpful? Give feedback.
-
Hello this also fixes: #7254 |
Beta Was this translation helpful? Give feedback.
-
I am having the impression that since I'm using this feature, I am unable to use |
Beta Was this translation helpful? Give feedback.
-
Stacks that are created with the 'Enable relative path volumes' option are marked as Limited control (This stack was created outside of portainer) since they are effectively created from outside by 'portainer/compose-unpacker'. |
Beta Was this translation helpful? Give feedback.
-
Can someone advice with this relative path option? But when I toggle the
I'm not sure if there is some value that should be 'valid' for this path or its more on the host configuration side. |
Beta Was this translation helpful? Give feedback.
-
the folder: |
Beta Was this translation helpful? Give feedback.
-
I've tried to make sense of the above discussion as to what it the future is for people in the community edition (I'm an individual, the business edition does not make sense for my use case). I can understand why the relative paths feature is paywall'd by the BE, but is there potential for something like #6390 (comment) to be in the CE? Speaking for myself I think being able to mount local files when deploying from Git (either by relative paths or by having a predictable volume name on the host) is a critical feature; I cannot use Portainer without this. |
Beta Was this translation helpful? Give feedback.
-
I've just started trying Portainer for my homelab and that's the first major obstacle I've encountered almost instantly. That's a no-go for me. |
Beta Was this translation helpful? Give feedback.
-
As the relative path volume feature has been rolled out to Portainer Business Edition for a while now, I'm closing this discussion for now. For future visitors to this thread, Portainer Business Edition is available for free for up to 3 nodes via our website, and includes relative path volume support for Git stacks (among other features). |
Beta Was this translation helpful? Give feedback.
-
Thanks in advance for your great work. What about relative paths and webhook deployment? Is there any incompatibility between them?
|
Beta Was this translation helpful? Give feedback.
-
Just spent a few hours going down this rabbit hole, for what now seems a waste of time 😖
Before I bite the BE 3-node bullet, is this ^ still the case? If so, not sure why I'd bother, since the whole reason I'm using Portainer's Git Repo functionality is to gain "Total" control |
Beta Was this translation helpful? Give feedback.
-
Is this feature coming to Portainer CE? |
Beta Was this translation helpful? Give feedback.
-
Problem statement
I'm unable to use relative paths for volumes when deploying from Git.
As an example, I have static HTML content in a git repo, as well as a yaml to deploy nginx that wants to use that static HTML.
I have the following compose yaml in my git repo:
And I have the static HTML in a dir in git called
static
.Deploy it:
Results in:
invalid mount config for type "bind": bind source path does not exist: /data/compose/56/stack/static
Which is referencing the Portainer volume.
And even if I'd mount the Portainer volume to my nginx container, I wouldn't know the compose id.
I’m using swarm, so the services are getting rejected
Click on the name of a task
At the moment I have to create a volume, put the static content in it in some other way and reference it as external:
Workaround on Docker and NOT using an Agent
To make this work on Docker, use the local Portainer environment.
Use the
--data
flag and use a bind mount for Portainer as well, so that the volume gets shared:So nginx has a bind mount with a relative path (which is on the docker host).
And it means that every container deployed via Portainer can access Portainer’s data
Deploying using an Agent
When using the Agent, we can't share the volume between the Portainer instance and where the stack is getting deployed.
(the bind mount for Portainer would be on a different host than the bind mount for the Agent)
And named volumes can't be shared between hosts either.
So that's currently not working.
Swarm
The stack in the first example above for nginx uses the relative bind mount of
./static
.However, that's not allowed for Swarm:
https://github.com/compose-spec/compose-spec/blob/master/spec.md#volumes
Considered solutions
Use named volumes and clone directly into that:
Automatically clone the repo in each remote instance directly.
e.g. allow the user to specify the name of the volume in the UI when deploying a stack/app from git. Assuming the volume exist, we then clone to that volume; the yaml for the container can then reference that volume reliably.
This could have severe security implications; the Agent would need to obtain the Git credentials.
However, when not using an Agent, we can’t mount a new volume to a running Portainer instance, so that’s why the agent has the bind mount
/var/lib/docker/volumes:/var/lib/docker/volumes
.Use named volumes and copy the files into them:
Automatically copy the cloned git files into a persistent volume.
Portainer clones Git, creates a persistent vol and copies the files into it. Then deploy the compose file with the persistence defined in the compose file repointed to the new populated volume.
This would require parsing the compose file to check any bind-mount paths in it for “relative-ness”, and then fix them.
(when using an Agent: after cloning the Git repo but before deploying, push the contents of the repo to the remote agent so that they are available there)
However, when not using an Agent, we can’t mount a new volume to a running Portainer instance, so that’s why the agent has the bind mount
/var/lib/docker/volumes:/var/lib/docker/volumes
.Use a network share:
Make a network shared volume that all nodes can see, and then copy the files into it.
Beta Was this translation helpful? Give feedback.
All reactions