How to create a custom template in Portainer to facilitate Docker deployments

0

Jack Wallen shows you how to create custom templates in Portainer to make your container development process more efficient.

Image: Gorodenkoff/Adobe Stock

Portainer has become my go-to for managing container deployments. This one-stop-shop makes building apps and services incredibly easy and supports nearly every step required for deploying complete, containerized apps.

One of the features included by Portainer is the ability to create custom app templates. With these app templates, you can create reusable manifests for full-stack apps. Think of it as your way to create, save, and use dockerfiles over and over again – all from the Portainer GUI. Using custom templates is a great way to simplify your workflow and lighten your development load.

SEE: Recruitment kit: Back-end developer (TechRepublic Premium)

What you will need

To work with custom templates, you will need a running instance of Portainer and an account to log in with. And that’s it: let’s get to work.

How to create a custom template

Login to Portainer

Point your web browser to your Portainer instance and log in with a user account that has permissions to create various assets on the platform.

Access the Custom Templates section

Click to expand the App Templates section in the left sidebar, then click Custom Templates (Figure A).

Figure A

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

Create the new model

I will show 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. Introducing the Portainer Custom Model.

In the top section of the add custom template page (Figure C), give the template a name – such as nextcloud-template – and a description.

Figure C

Image: Jack Wallen/TechRepublic. Created a new custom template to use in Portainer.

Be sure to select Linux as the platform and, if available, select Swarm in the type. Once you’ve taken care of that, scroll down to the Build Method section. Paste the following content into the Web Editor section (Figure D). Be sure to change 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

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

Scroll down and click Create Custom Template to save your work.

How to deploy the model

We can now use our model again and again. In the Custom Template section (Figure E), click on 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 Stack.

Figure F

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

After a while, the stacked containers will be ready for use.

You can reuse this custom template as often as you want. One thing to keep in mind, however, is that if you reuse it while a previous deployment is running, you’ll need to change the external port number for Nextcloud, otherwise it won’t work because the port in the template is already in use.

And that’s all there is to creating and using custom templates in Portainer. Take advantage of this newfound efficiency.

How to learn more about Docker

If you want to learn more about Docker, don’t miss these resources from the TechRepublic Academy:

Subscribe to TechRepublic How to make technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.

Share.

Comments are closed.