As a longtime user of Hetzner, I've consistently found it to be one of the best hosting solutions available. The performance and features have generally met my needs, except when it comes to storage capacity. Hetzner's maximum configuration offers 320 GB of disk space. For most applications, this is sufficient, but a challenge arises when dealing with larger datasets, such as those used by my PostgreSQL databases.
Before diving into the technical adjustments I had to make, it's essential to understand the difference between Docker volumes and bind mounts.
Docker volumes are stored within the Docker host’s filesystem and are managed by Docker. Here are some benefits of using Docker volumes:
Bind mounts may have a simpler concept where a directory or file on the host is mounted into a container. Here are some reasons why bind mounts can be advantageous:
Given these points, bind mounts offer a better solution when handling large databases or datasets that require frequent updates and faster access speeds, which is why I decided to make the switch.
Initially, my PostgreSQL service was configured as follows in my Docker Compose file:
The first step was to set up the directory that would be used for the bind mount:
Ensuring the ownership of the directory matches the user and group expected by the PostgreSQL container is crucial. To confirm the correct ownership, I executed the following commands:
This output confirmed the user ID and group ID:
Then I changed the user and group ownership of the directory to match Docker volume files.
After setting the permissions, I updated the Docker Compose file to use a bind mount:
The final step involved moving the existing data to the new directory:
Once the data was successfully transferred, I restarted the services:
Although bind mounts require a bit more initial setup and caution, the performance gains and flexibility in managing the data are well worth it. For anyone running into similar storage constraints with Docker, considering bind mounts might provide a suitable solution.