Stacks (docker compose)
Time Required
30 Minutes
Difficulty
Low - Moderate
Required Knowledge
Portainer, Docker compose
What is a Stack?
Stacks is how Portainer handles Docker Compose files, which are infrastructure as code documents for spinning up multiple containers, volumes and networks in 1 go.
Most docker container developers now provide example compose files with their projects. Its also possible to Google and find examples online
For example, you may have a service that has a separate container for
a database
a web app
back end compute
The database and back end compute may be on Network 1, while the web app is on Network 2.
All 3 containers have access to the same 'config' volume, but the database and webapp have their own unique volumes
The database and backend need the same credentials to the 2 systems can talk, but the web app has separate credentials for the gui. These are environmental variables
Instead of manually setting up and inputting environmental variables, networks and volumes for each container this can all be written into the compose and and span up in 1 click. This also makes the set up system agnostic.
Deploy your Stack
In this example, we're going to deploy the Ombi compose file we created in Create your first compose file
Log into Portainer
If you set up Edge Agents, click on the host you want Ombi to exist on
On the left hand menu, select 'Stacks'
Click on 'Add stack'
Give your stack a name (eg "ombi")
Build method = Repository
Tick 'Authentication'
Username = Github Email
Personal Access Token = PAC saved in Create your GitHub Repo
Repository URL = the URL of your repo + .git (eg "https://github.com/trentnbauer/agg.local.git_"_)
Compose path = docker-compose/ombi.yml
Tick 'Automatic updates' You should see a page similar to this
Scroll down to the 'environment variables' section and add the following variables
TZ
BASE_URL
PORT_HTTP

Provide your TZ per the 'tz identifier' here
Provide a base url, if you are using one (not required)
Provide the port that Ombi will use
Click on 'Deploy the stack'
In this example, we're going to deploy the Ombi compose file we created in Create your first compose file
Log into Portainer
If you set up Edge Agents, click on the host you want Ombi to exist on
On the left hand menu, select 'Stacks'
Click on 'Add stack'
Give your stack a name (eg "ombi")
Build method = Repository
Repository URL = the URL of your repo + .git (eg "https://github.com/trentnbauer/agg.local.git_"_)
Compose path = docker-compose/ombi.yml
Tick 'Automatic updates' You should see a page similar to this
Scroll down to the 'environment variables' section and add the following variables
TZ
BASE_URL
PORT_HTTP

Provide your TZ per the 'tz identifier' here
Provide a base url, if you are using one (not required)
Provide the port that Ombi will use
Click on 'Deploy the stack'
While this is easier than using GitOps, its no where near as powerful and will require manual intervention to update containers.
I do this often when I am building compose files, as its easier to work with the native editor as aposed to GitHub
Log into Portainer
If you set up Edge Agents, click on the host you want Ombi to exist on
On the left hand menu, select 'Stacks'
Click on 'Add stack'
Give your stack a name (eg "ombi")
Build method = Web editor
Paste your compose file into the web editor and make any adjustments required
If you have any issues, refer to the Notifications tab at the top of the page;

Most Portainer errors can be resolved with a simple Google search but I also have my own troubleshooting list here
Updating Stacks
If you have used GitOps, Portainer will check in with GitHub and download the updated compose file and update the container image.
You can tell Portainer to manually pull by;
Browse to the stack
Click on 'Pull and redeploy'
If you have not used GitOps you will need to edit the stack yourself as needed
Last updated