IT Engineer with Tool Cart Working on a Laptop Computer, he Holds a Hard Drive. He Stands at a Corridor of a Large Data Center Full of Rack Servers.
Image: Gorodenkoff/Adobe Stock

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

Image: Jack Wallen/TechRepublic. Accessing the Custom Templates section in Portainer.

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

Image: Jack Wallen/TechRepublic. The Portainer Custom Template overview.

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

Image: Jack Wallen/TechRepublic. Creating a new Custom Template to be used in Portainer.

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"



image: nextcloud:latest

restart: unless-stopped


- 8081:80


- MYSQL_HOST=mysql

- MYSQL_DATABASE=nextcloud

- MYSQL_USER=nextcloud

- MYSQL_PASSWORD=nextcloud


- nextcloud:/var/www/html


image: mysql:8.0

restart: unless-stopped


- MYSQL_DATABASE=nextcloud

- MYSQL_USER=nextcloud

- MYSQL_PASSWORD=nextcloud



- mysql:/var/lib/mysql




Figure D

Image: Jack Wallen/TechRepublic. The dockerfile for a Nextcloud deployment makes for a great template.

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

Image: Jack Wallen/TechRepublic. Our new Custom Template has been created and can now be used.

In the resulting window (Figure F), give the stack a unique name and click Deploy The Stack.

Figure F

Image: Jack Wallen/TechRepublic. Deploying a new stack from our template.

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:

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.