problem with portainer volume reddit / selfhosted ---------------------------------------------------------------------- kamiar_ · 2023-11-16 23:28 Hi, so i got a few stack setups but if i redeploy the image or update the image or make changes in a stack config and click deploy all the data is gone, its back to the setting the container from scratch again here is an example of a stack i got running version: '3' \#-------------------------------------------------------------------- -# \# Homarr - A simple, yet powerful dashboard for your server. # \#-------------------------------------------------------------------- -# services: homarr: container\_name: homarr image: [ghcr.io/ajnart/homarr:latest](https://ghcr.io/ajnart/homarr:latest) restart: unless-stopped volumes: \- /volume1/docker/app/data/configs \- /volume1/docker/app/public/icons \- /volume1/docker/homarr/icons:/app/public/icons \- /var/run/docker.sock:/var/run/docker.sock \- /volume1/docker/homarr/data:/data ports: \- '7575:7575' environment: ​ ​ ---------------------------------------------------------------------- Ursa_Solaris · 2023-11-16 23:49 > volumes: > - /volume1/docker/app/data/configs > - /volume1/docker/app/public/icons It looks like these are incorrect, there's no colon so the volume isn't being mounted anywhere inside the container. I'm actually surprised that even runs, I would expect it to throw a syntax error. ---------------------------------------------------------------------- kamiar_ · 2023-11-17 00:05 you be shocked then got 40+ of them running this way lol, how do i fix it ? where am i adding colon ? ---------------------------------------------------------------------- thekrautboy · 2023-11-17 00:36 /r/Docker but you should really just take a look at the documentation. ---------------------------------------------------------------------- Ursa_Solaris · 2023-11-17 01:39 It should be formatted like `volume:location`, and the volume can be either a volume created in Docker, or a bind mount to a directory on the host filesystem. But it's always host on the left side, container on the right side. For example: `example-data-volume:/app/data` `/example/directory/config:/app/config` If it starts with a slash, it's a directory on the host's filesystem. If it doesn't, it's a volume created in docker. ---------------------------------------------------------------------- kamiar_ · 2023-11-17 16:40 so the volumes portainer creates isn't the right way or creating volumes manually doesn't work? ---------------------------------------------------------------------- Ursa_Solaris · 2023-11-17 19:11 Okay, I dug into it and it turns out this is a valid syntax, but for another feature I was totally unaware of: anonymous volumes. Basically, you're creating a brand new volume every time you run the container because you didn't assign a name or location to it. This is desirable for certain situations where you want the data to be saved, but not reused. If you go into the Volumes menu on Portainer, you'll probably see a bunch of volumes listed as "unused" with randomly generated strings as names. You want to reuse the data though for this case, so to get persistence you either need to create a named volume in Portainer, or bind it to a direct folder on the host. If you want to handle it as a named volume, this is an example what it would look like: ``` services: bookstack: image: lscr.io/linuxserver/bookstack container_name: bookstack volumes: - bookstack-config:/config volumes: bookstack-config: name: bookstack-config ``` The `volumes:` under the `services:` header tells the container which volume to use and where to put it; the separate `volumes:` header below that is used to assign options and features. By using `name: bookstack-data` I tell it to look for a volume with that exact name, and if it doesn't exist, create it. If you don't set the `name`: attribute, it'll create stuff that looks like `SERVICENAME_VOLUMENAME-1` instead, so it's better to give it the *exact* name you want. If you want to manually control it entirely yourself, create one manually from the Portainer volumes menu, then remove `name: bookstack-data` and add `external: true`. This tells it to never create it and only look for one that already exists. If you want to just create a raw folder on your host system and use that, it would look like this: ``` services: bookstack: image: lscr.io/linuxserver/bookstack container_name: bookstack volumes: - /example/directory/bookstack-config:/config ``` You don't need the separate `volumes` definition if you do this, because there's no options to set. You're just telling it to use a raw folder as if it was a volume. This makes it easier to access the files from outside the container.