Portainer has become my go-to for managing container deployments. This one-stop-shop makes it incredibly easy to build apps and services and takes care of nearly every step required for full-stack, containerized app deployment.
One feature Portainer includes is the ability to create custom app templates. With these app templates, you can create reusable manifests for full-stack applications. Think of this as your way to create, save and use dockerfiles over and over – all from within the Portainer GUI. Using custom templates is a great way to simplify your workflow and ease your development burden.
SEE: Hiring kit: Back-end Developer (TechRepublic Premium)
What you’ll need
To work with custom templates, you’ll need a running instance of Portainer and an account with which to log in. And that’s it: Let’s get to work.
How to create a custom template
Log in to Portainer
Point your web browser to your Portainer instance and log in with a user account that has the necessary permissions to create various assets on the platform.
Access the Custom Templates section
Click to expand the App Templates section in the left sidebar and then click Custom Templates (Figure A).
Figure A
Create the new template
I’m going to demonstrate how to create a custom template for Nextcloud deployments. In the resulting window (Figure B), click Add Custom Template.
Figure B
In the top section of the Custom Template add page (Figure C), give the template a name – such as nextcloud-template – and a description.
Figure C
Make sure to select Linux as the platform and if available select Swarm from the type. Once you’ve taken care of that, scroll down to the Build Method section. Paste the following content in the Web Editor section (Figure D). Make sure to edit passwords to be strong and unique:
version: "3"
services:
nextcloud:
image: nextcloud:latest
restart: unless-stopped
ports:
- 8081:80
environment:
- MYSQL_HOST=mysql
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=nextcloud
volumes:
- nextcloud:/var/www/html
mysql:
image: mysql:8.0
restart: unless-stopped
environment:
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=nextcloud
- MYSQL_ROOT_PASSWORD=nextcloud
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
nextcloud:
Figure D
Scroll to the bottom and click Create Custom Template to save your work.
How to deploy the template
We can now use our template over and over. In the Custom Template section (Figure E), click the newly-created custom template.
Figure E
In the resulting window (Figure F), give the stack a unique name and click Deploy The Stack.
Figure F
After a moment, the stack containers will be up and ready to use.
You can reuse that custom template as often as you like. One thing to keep in mind, however, is that if you re-use it while a previous deployment is running, you will have to change the external port number for Nextcloud, otherwise it will fail to run because the port within the template is already in use.
And that’s all there is to creating and using custom templates in Portainer. Enjoy that newfound efficiency.
How to learn more about Docker
If you want to learn more about Docker, don’t miss these resources in the TechRepublic Academy:
- Hacking and Securing Docker Containers
- The Linux & Docker Coding Bundle
- The Docker and Kubernetes Certification Training Bundle
Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.