Updated News Around the World

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

Jack Wallen shows you how to build custom templates in Portainer to help make your container developer process more efficient.

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"

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 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.

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

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! NewsUpdate is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – [email protected]. The content will be deleted within 24 hours.