Daiwei
Daiwei

Reputation: 43676

Docker how to add volume to a running container?

I got a PostgreSQL instance running in a ubuntu docker container. I put the database dir in a volume which is also shared with the host system by running:

sudo docker run -d -p 10001:5432 -v ~/logs/postgres:/var/log -v ~/postgres-data:/var/lib/postgresql/data --name db postgresql

However, the /var/lib/postgresql/data is becoming bigger and the host system is running out of space. Is there any way I can add additional volume to a running container? So I can create a table space in PG (http://www.postgresql.org/docs/9.3/static/manage-ag-tablespaces.html)? Or any other alternatives?

Upvotes: 4

Views: 5832

Answers (2)

Muhammad Soliman
Muhammad Soliman

Reputation: 23876

A workaround for this is to commit the container to an new image then run the image again with new volume specified, I've no idea that might work for your case however it is already tested before:

Simple you can commit your existing container and then run it with your new mounts or volumes, follow the following steps:

Take a commit from current running container to a new image:

$ docker commit containerID newImageName

Run now the new image with new volumes you need:

$ docker run -ti -v $(pwd)/dir1:/dir1 newImageName /bin/bash

There is also a bash script described here which might be helpful too but honestly I did not try yet.

Upvotes: 0

Markus
Markus

Reputation: 1485

as your files might just be stored on your disk at /var/lib/docker/[aufs|btrfs|?]/mnt you should increase the size of the mounted volume as you would do with a normal instance, you might could mount another volume right inside the running container, but it would be a hack anyway

Upvotes: 0

Related Questions