Creating a Docker Volume for Gogs and PostgreSQL Using NFS

Creating a Docker Volume for Gogs and PostgreSQL Using NFS

Docker volumes are a crucial part of managing data in Docker containers, allowing for persistent storage that can be shared among multiple containers. One of the robust options for Docker volumes is using Network File System (NFS), which allows for network-based file sharing. This article will guide you through the process of creating Docker volumes for Gogs (a self-hosted Git service) and PostgreSQL using NFS.

Part III: Storage, the Docker Way

Prerequisites

  1. NFS Server: Ensure you have an NFS server set up and running.

  2. Docker: Install Docker on your host machine.

  3. Basic knowledge: Familiarity with Docker, Docker Compose, and basic NFS concepts.

To create a Docker volume for both Gogs and PostgreSQL using NFS, we need to set up an NFS server and then mount the NFS volume into your Docker containers.

1. Set Up NFS Server

First, we need to have an NFS server running and accessible from your Docker host.

Installation guide - https://ubuntu.com/server/docs/network-file-system-nfs

  • Install ssh-server on host

apt install nfs-server -y

  • Edit /etc/exports

\>Make dir for NFS

\>Refresh /etc/exports

2. Create Docker Volume

Now, on Docker host machine, create a Docker volume that mounts the NFS share:

3. Create a docker network

4. Start PostgreSQL Container with NFS Volume

Start the PostgreSQL container, mounting the NFS volume for data persistence:

5. Start Gogs Container with NFS Volume

Start the Gogs container, also mounting the NFS volume for its data:

6. Access port 3000 for interface

7. Check NFS server Dir for data

By following these steps, you can effectively create and use a Docker volume for both Gogs and PostgreSQL, leveraging NFS for data persistence across containers.

Conclusion

By following these steps, you can set up persistent storage for Gogs and PostgreSQL using NFS with Docker volumes. This setup provides a scalable and robust solution for managing data in a Dockerized environment. With the flexibility of NFS, you can easily expand and manage storage across different servers, ensuring your data is always available and secure.


Linkdin