brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: migrating a stack in Portainer does not move its volumes

Portainer
~/tips/tip-portainer-migrate-stack

docker run --rm -v myvolume:/data -v $(pwd):/backup alpine \

Copies a stack to another Portainer environment, though its volume data stays where it was.

Portainer can copy a stack to another environment in a few clicks. It is a nice feature and it also has a trap.

Open the stack and select Migrate this stack. Choose the destination environment, optionally give it a new name, and click Migrate. If you want to keep the original, use Duplicate on the same screen instead.

The docs say migrating does not relocate the content of any persistent volumes attached to the stack. The new stack starts with empty volumes. For a stateless web app that is fine. For a database it is not.

So I would move the data myself first. One way is to copy the volume content with a throwaway container and tar, or to restore from the app’s own backup on the new side.

docker run --rm -v myvolume:/data -v $(pwd):/backup alpine \
  tar czf /backup/myvolume.tar.gz -C /data .

Caveat on the Kubernetes side: migrating a Docker stack to Kubernetes uses Kompose and the docs call it experimental. Do not use that on something you care about.

For databases I would stop the stack first, copy the volume, then start the migrated one. A copy of a running database can be inconsistent, and the docs do not promise anything about it. A backup made by the app itself is safer than a file copy.

Further reading: Migrate or duplicate a stack, On this site: in a Portainer stack, env_file stack.env is not the same as a .env file, On this site: turn on Re-pull image in a Portainer Git stack so updates really update

More Portainer tips Choose Polling in a Portainer GitOps update when your Git host can't reach Portainer Put Portainer environments in groups and give users access to a whole group Portainer's Edge Agent checks in every 5 seconds, and you can change that docker run -d -p 9001:9001 --name portainer_agent --restart=always \ Deploy the container → Replace All Portainer tips (28) All topics

Link