Skip to content

Instantly share code, notes, and snippets.

@andrius
Last active November 16, 2022 16:03
Show Gist options
  • Save andrius/18fcfed9c1ebc4a3932af1a739630d05 to your computer and use it in GitHub Desktop.
Save andrius/18fcfed9c1ebc4a3932af1a739630d05 to your computer and use it in GitHub Desktop.
#howto rename #docker volume

Say, folder with docker-compose files was renamed or we do merging volumes etc. Then we shall rename docker volume. Because docker natively does not support renaming, we shall create it, then copy data, then inspect new volume, test and delete old one at the end

Volumes:

docker volume ls
DRIVER              VOLUME NAME
local               andrius_mysql     <-- old
local               databases_mysql   <-- new

Copyng data with permissions and user owenship info, at the end sh will be executed to inspect data:

docker run -ti --rm \
  -v andrius_mysql:/db/old \
  -v databases_mysql:/db/new \
  alpine sh -c 'apk --update --no-cache add rsync mc && rsync -avzrP /db/old/ /db/new && sh'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment