How to create a persistent Docker volume
Our Bitwarden application is currently running inside the Docker containers, some of the files and directories are not persistent, which means all the files we have updated straight inside the container will be lost once the container restarted.
Docker images
All the containers are relying on each image.
It means when we restart the container it will pull the default data from their own image.
Docker Compose file
The compose file contains all the configurations for each container, the compose file is currently located at /root/bwdata/docker/ docker-compose.yml.
Creating a persistent volume
In this example, we will be creating a volume for the container bitwarden-web.
Go inside the directory where the compose file is located.
cd /root/bwdata/docker
And run these to list all the container names.
docker ps
Once you get the container name you will need to go inside the container to locate the file you need and copy it to the host server.
docker exec -ti bitwarden-web bash
In this example, we will make a persisted volume for the /app/image directory on the container bitwarden-web then exit from the container once you get the path.
Then you need to copy the whole directory to the host.
docker cp bitwarden-web:/app/images .
Then check it on your current location.
You need to turn off the containers now, make sure you are inside the directory /root/bwdata/docker where the compose file is located.
docker-compose down
Once the container is down, you will need to update the compose file.
vi docker-compose.yml
And add the location -./location-on-host:/target/location-inside-the-container.
Then save and exit.
Then power up the containers.
docker-compose up -d
And wait for all the containers to boot up.
To test it, create a text file inside the persistent volume.
And see if it inside the container.
The /app/image directory on the container bitwarden-web is now persisted.