Docker Community Forums

Share and learn in the Docker community.

Create volume on running docker container?


I forgot to add volume in docker-compose.yml when launched project.
The missing volume is ment to store letsencrypt certificates.

So if my server reboots I will lose certificates.
Usually I would just docker compose down, add needed volume, and reconfigure everything again.(This would be absolutely last option)
I cant turn off containers since projects are already in production.
Is there a way to create a volume and attach to it /etc/letsencrypt directory while containers are up and running?

My goal is to preserve letsencrypt directory if server for examples shuts down or containers crashes.

Huge appreciation of solution.

Please help, thanks in advance.

You want something like the attach/detach of networks for running containers, but just for volumes. I am afraid there is no such option.

You could ease the pain by using docker cp to copy the files you need from the container to the host (double check if your realy copied all relevant files!), add the volume to your compose file and redeploy. If everything is done right, you should have minimum downtime. You might want to perform this exercise outside of buisness hours to reduce stress while troubleshooting when things shouldn’t work as expected.

In case you aim for named volumes instead of bind-mounts, make sure to create a one-shot container with the named volume + a bind-mount of the host folder you copied your files into and then copy the files from the bind-mount to the volume. Once this is done add the volume to the compose file and redeploy then.

Thank you for your input, appreciate, will do like that.