Portainer is a great tool for deploying and managing your Docker containers. With this platform, you can manage nearly every aspect of your container lifecycle, such as images, networks, stacks, events, hosts, users, registries, environments, and volumes.
Volumes are crucial to your container deployments, as they’ll show how you can deploy apps and services with persistent storage. Being able to create and manage those volumes with the Portainer GUI can make this task considerably easier.
I want to show you how easy it is to create a new volume in Portainer.
What you’ll need
First, you’ll need a running instance of Portainer (and an admin user to log into the system). I’ll be showing you two different ways to create a volume: A simple volume on local storage and a remote volume via CIFS (in my instance, Samba).
Let’s create some volumes.
How to create a local volume with Portainer
The first type of volume we’ll create is of the local sort. This is the simplest form and is stored on the local machine. To do that, log into Portainer and click Volumes in the left navigation. In the resulting window (Figure A), click Add volume.
In the Create volume window (Figure B), give the new volume a name and then either select Administrators (to restrict access to only those who belong to the administrator group), or Restricted (to configure a group or user who will have access).
Click Create the volume and Portainer will take care of the magic. You’ll be returned to the Volume list page, where your new volume will be listed (along with its mount point–Figure C).
How to create a remote volume with Portainer
We’ll next create a persistent volume on a remote share. To do this, go back to the Volumes list page and click Add volume. On the Add volume page, give the volume a name and then click the ON/OFF slider for Use CIFS volume. You should now see all the necessary fields for creating the CIFS volume (Figure D).
The information should be fairly straightforward (if you know the details of your hosted CIFS share). For example, if your share is the folder /home/jack/data on IP address 192.168.1.62, you’d fill in the information like so:
- Address: 192.168.1.62
- Share: /data
- Username: jack
- Password: User jack’s password
You can also restrict access to the share to either admins only or a group/user. After you’ve filled out the necessary information, click Create the Volume and you’re done.
How to use a new volume in Portainer
Let’s create a new container and make use of our new volume. Click Containers in the left navigation. In the resulting window, click Add container. We’ll deploy a simple nginx container that uses our new volume. Give the container a unique name, type nginx in the Image section, and then click the Volumes tab near the bottom of the window.
In the Volume section (Figure E), click map additional volume.
In the resultant screen (Figure F), type a path that will be used to mount the new volume, and then (from the drop-down), select the new volume you just created.
After you’ve successfully filled out all the details for your container, click Deploy the container and it should successfully deploy. Once the deployment is completed, you should see it listed in the Containers listing. Click on the container name and you can see it has successfully mapped our new persistent volume (Figure G).
Congratulations, you’ve created your first Docker volumes with the ease of Portainer.
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.