Fixing Dumb Docker Volume Names

Fixing Dumb Docker Volume Names
Photo by Rubaitul Azad / Unsplash

I frequently use Portainer and its Stacks feature (which is really just Docker Compose in a fancy hat...) to spin up all manner of random junk. It is probably the laziest way to get from nothing, to a full working service with a web GUI. Here's a list of cool stuff you can run at home, most of which will run via docker. I'll have more to come on this in the future.

While working with Docker volumes I occasionally run into the issue (as you likely have, since you are reading this...) of the directory names not corresponding to the actual names of the volumes.

My Docker-Compose volume declarations.

Above is a snippet of the Compose file for my Nginx Proxy Manager Instance.
As you can see, the volumes are named nginx_data and nginx_letsencrypt.

Nonsense docker volume names

So why are they instead named this pile of crap? The reason is simple.

Correctly added external flags

Without the external: true flag, docker will assume you haven't already created the volumes, As a result it will create the volumes and name them the way it wants

But I want them named correctly!

Well, it's not as simple as just adding the external flags. You could end up deleting your existing data, or not being able to see the volumes within portainer. We have a few steps to get there first.

Stop the stack.
Go to the volumes section in portainer, and add the correctly named volumes.

Now we need to hop into the command line, and remove the folders portainer just created. All the docker volumes are in /var/lib/docker/volumes

First remove the NEW folders portainer created
Now move (rename) the old folder to where the new folder was.
Head back to your compose file, add the external flags, and start the stack.

Now the volumes will be named correctly, the folders will be named correctly, and the volumes will actually show up within the volumes section in portainer. Yeehaw.