Home > OS >  Rename Docker Volume on Docker Desktop
Rename Docker Volume on Docker Desktop

Time:08-05

Is it possible to rename a docker volume? I want to change the volume names of the existing container. I see that config.json and hostconfig.json has the volume details in it.

docker run -di -p 8083:443 -v app_main_db_test_1:/var/lib/pgsql/data  -v app_main_conf_test_1:/var/www/ ubuntu

I want to change app_main_db_test_1 to app_main_db and app_main_conf_test_1 to app_main_conf

CodePudding user response:

Figured it out. Thanks to this github post.

# Create new Volume for DB and copy files from old volume
docker volume create --name app_main_db 
docker run --rm -it -v app_main_db_test_1:/from -v app_main_db:/to alpine ash -c "cd /from ; cp -av . /to"

# Create new Volume for conf and copy files from old volume
docker volume create --name app_main_conf
docker run --rm -it -v app_main_conf_test_1:/from -v app_main_conf:/to alpine ash -c "cd /from ; cp -av . /to"


# Start the container using new volumes
docker run -di -p 8083:443 -v app_main_db:/var/lib/pgsql/data  -v app_main_conf:/var/www/ ubuntu

# Delete old volumes
docker volume rm app_main_db_test_1
docker volume rm app_main_conf_test_1

CodePudding user response:

as far as i know there are no ways of renaming docker volume so far. There is an open github issue, which indicates there is no solution to the topic yet.

But there are a few useful ways how to do so. Since you are saying you use Docker Desktop you could check this comment:

docker volume create --name <new_volume>
docker run --rm -it -v <old_volume>:/from -v <new_volume>:/to alpine ash -c "cd /from ; cp -av . /to"
docker volume rm <old_volume>

Which should do exactly what you are planning to do.

  • Related