Skip to main content

Using and configuring internal volumes

Overview

Internal volumes are a key feature in Docker that allow containers to persist data without depending on the host filesystem. Unlike bind mounts, internal volumes are managed by Docker itself, making them ideal for storing application data in a controlled and isolated environment.

In this tutorial, we will explain what internal volumes are, how to configure them in a docker-compose.yaml file, and guide you through two practical exercises: one for using volumes locally and another for deploying them on a Barbara Edge Node.


Videotutorial

See also...

What Are Internal Volumes?

Internal volumes are directories created and managed by Docker within its storage system. These volumes persist across container restarts, but they are not tied to a specific directory on the host machine, ensuring a cleaner and more portable approach to data storage.

Key Benefits of Internal Volumes:

  • Data persistence: Data remains intact even if the container is restarted or removed.
  • Host independence: Volumes are stored in Docker’s internal storage, making applications more portable.
  • Improved security: Containers access only the data they need without exposing host directories.
  • Simplified backup and migration: Volumes can be backed up and moved across different environments.

Configuring Internal Volumes in docker-compose.yaml

To define an internal volume in a docker-compose.yaml file, use the volumes directive inside a service and declare the volume under the top-level volumes section.

Example Configuration

version: '3.8'
services:
filebrowser:
image: filebrowser/filebrowser:latest
ports:
- "8080:80"
volumes:
- filebrowser_data:/srv

volumes:
filebrowser_data:

In this configuration:

  • The filebrowser_data volume is created and used to store data inside the /srv directory in the container.
  • The volumes: section ensures the volume is properly managed by Docker.
  • This volume will persist even if the container is removed, unless explicitly deleted.

Hands-on Practice 1: Using Internal Volumes Locally

Let's walk through an example of using internal volumes with the Filebrowser application.

Step 1: Create a docker-compose.yaml File

Create a file named docker-compose.yaml with the following content:

version: '3.8'
services:
filebrowser:
image: filebrowser/filebrowser:latest
ports:
- "8080:80"
volumes:
- filebrowser_data:/srv

volumes:
filebrowser_data:

Step 2: Start the Container

Run the following command to start the service:

docker-compose up -d

Step 3: Access the Filebrowser Interface

Open a browser and go to http://localhost:8080. You should see the Filebrowser web interface, which is storing its data in the filebrowser_data volume.

Step 4: Verify Volume Data Persistence

  1. Stop the container:
    docker-compose down
  2. Restart the service:
    docker-compose up -d
  3. Open Filebrowser again at http://localhost:8080 and verify that your stored data is still there.

Step 5: Remove the Volume (Optional)

To completely remove the volume, use:

docker volume rm $(docker volume ls -q --filter name=filebrowser_data)

Hands-on Practice 2: Deploying Filebrowser with Internal Volumes on a Barbara Edge Node

Now, let's deploy the Filebrowser application using an internal volume to a Barbara Edge Node.

Step 1: ZIP the docker-compose.yaml File

Compress the folder containing the docker-compose.yaml file:

zip -r filebrowser_app.zip ./

Step 2: Upload the Application to Barbara’s Library

  1. Go to your Barbara Panel’s Library.
  2. Click on "Add New Application" and name it filebrowser.
  3. Once created, add a new version and upload the filebrowser_app.zip file.

Step 3: Deploy the Application to an Edge Node

  1. Select an edge node from your Barbara Panel.
  2. Click "Add Card" and choose "Add a New Application".
  3. Select the filebrowser application and deploy it to the node.

Step 4: Access the Filebrowser Interface

  1. Open a browser and navigate to http://[IP_OF_YOUR_NODE]:8080.
  2. You should see the Filebrowser interface, now running on your remote edge node.

Step 5: Verify Data Persistence on the Edge Node

  1. Stop the application from the Barbara Panel.
  2. Restart it and check that previously uploaded files remain available.

Step 6: Manage Volumes in Barbara Panel

  1. Navigate to the "Storage" section in the Barbara Panel.
  2. Locate the filebrowser_data volume and verify its content.
  3. Optionally, remove the application and check if the volume remains, ensuring persistence.

Step 7: Stop or Uninstall the Application

  1. In the Barbara Panel, navigate to the application card.
  2. Stop the application or uninstall it if no longer needed.

Summary

Internal volumes provide a clean and efficient way to manage persistent data within Docker containers. Unlike bind mounts, they ensure host independence and security while simplifying deployment. Using internal volumes in Barbara’s platform enables reliable data persistence on edge nodes, allowing applications to maintain state even after restarts or redeployments.