HA Docker Installation method - docker compose or Portainer?

I am pretty new to Docker and Portainer. I have Portainer running on Ubuntu and would like to install HA as a container, preferably using Portainer.

I’ve been following some tutorials on how to install HA as a container. The tutorials use different installation methods, some using docker compose, some using Portainer.

Sorry to be slightly off topic, but I have a few questions that I am hoping someone with some experience in installing HA as a container may be able to answer.

I’m a bit confused about the relationship between docker compose and Portainer.

Is there a relationship between docker-compose.yml files and Portainer?
Does Portainer create a docker-compose.yml file when setting up a new container? If so, where is it stored?

If I use docker compose to install a container, will I see the container in Portainer and be able to manage it from there? Or should I stick with Portainer to handle the installation to keep things cleaner?

Hoping someone can provide some guidance.

Cheers
Neil

I’m a noob at docker still after a couple years, but I do think it is a great tool. The docker compose thing is something I try to stay away from, I know it is my lack of knowledge. But seems like more often than not when I am trying to use it to setup a container, there is error or quirk that requires me an hour to google and figure out.

I use Portainer to start, stop, delete and look inside my existing containers. Also to clean up images. It too as a very useful tool.

To create new containers, I most often use the docker cli tools. More often than not, I find there are command line things that need doing before creating a container. So I am at a command prompt for these, so just use the docker pull and docker run command as well to get the container up and running.

Yes using both the docker-compose way and the docker run way, portainer will see the new container within a few seconds and show it’s status.

Below is an example my standard routine to get a new Home Assistant version up and running in docker with my pull and run steps.

Good hunting!

docker pull homeassistant/home-assistant:2021.12.10

docker run -i -t -d --name="home-assistant-2021.12.10" \
   -v /home/user/homeassistant:/config \
   -v /media/:/media \
   -v /etc/localtime:/etc/localtime:ro \
   --net=host \
   homeassistant/home-assistant:2021.12.10

1 Like

Portainer uses compose syntax to define so-called stacks. You can copy and paste compose files into the Portainer stack editor an run the stack.

There is no visual editor for stacks in Portainer, thus no export of compose files. The configuration of Portainer, incl. stacks is saved in a volume.

If containers and stacks get started from within Portainer, you have full management capabilities using the Portainer UI. Otherwise you are limited to observing.

I’m still learning. I’m not clear on what the additional functions I get by creating and/or starting a container from Portainer vs. the docker commands at command line. I think if I create and start a container at command line, it creates a entry in Portainer’s ‘container list’ web page from which I can stop/start/inspect/shell in to/view logs. Is that ‘observing’? What additional functions would be in ‘full management’?

As I said in earlier post, my routine is to usually create my containers from the command line. Then I usually start/stop them from Portainer web gui. Also I use Portainer to check docker logs as quick way to see if there are issues.

Thx!

Not much and not on container level, but with “stacks”. Just checked it (as I am using Portainer to manage “stacks” on multiple Docker hosts): You cannot delete a docker-compose stack, that was created outside of Portainer. You can however fully manage the containers that have been created by the (external) docker compose run inside Portainer.

You don’t need Portainer to run a Home Assistant container stack, docker-compose is sufficient. In that context, Portainer is nothing but a conventient, visual interface to the docker runtime.

Docker is a beautiful technology which help many noobs like us to be able to use many apps, in which manually will be a lot of heartache to pass by.

Anyway as long you install docker + docker-compose correctly then docker-compose is the best way. Why? because you will be able to backup everything and you can always call it in the future.
Using a command docker run ← is simple but sometimes in the near future you will surely forget on what being written by yourself especially the environment. I learn this the hard way.

As Portainer is a helping tools for updating and monitoring, but again in my opinion its better to install it using docker-compose.

Official Docker-Compose

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /PATH_TO_YOUR_CONFIG:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

And the official link Linux - Home Assistant

I never use docker-compose.

I use the docker run command via cli to create all my containers and I have a text file documenting all of the various run command set ups.

and then I use Portainer to manage everything after that (updates mostly but starting/stopping too occasionally).

the only time I use the cli after first install is if I need to delete a container and re-install it then I delete it with Portainer and re-install via the cli but that happens only very rarely tho.

I also manage everything through Portainer. Like someone mentioned above, I use the “stack” function of portainer where I can just copy the contents of docker compose into the stack page to create the container. The nice thing about that is you don’t have to use the command line at all, and it also automatically checks the format of the yaml as you go along highlighting any potential errors.

Since using portainer, the only thing I have to use the command line for now with docker is if portainer itself needs to be updated.

Here’s a good writeup about how to use docker-compose in Portainer Stacks:

Actually, running a single container does not even require compose …

Definitely true, but the whole point of compose is if you have a lot of options to specify, putting them all in a single run command can become difficult to manage and the command becomes very long. It probably depends a lot on the container you are running though. Installing Home Assistant container with the run command is probably fine (and even recommended by the official install instructions - Linux - Home Assistant ) since there aren’t a lot of options to specify, but installing something like the SWAG/NGINX container has tons of options to specify which would be a lot to do as a single run command (see sample compose here) - Nginx Reverse Proxy Set Up Guide – Docker - #272 by mwav3

A main reason I started using compose in the first place was many tutorials and instructions are written around using compose versus the run command, especially with more complex docker containers. Then I found the “portainer way” I linked above which has been my go to ever since. But like anything, there are definitely multiple ways to do this that will come down to user preference, past experience, and containers/programs used.

Also useful, if you ever want to take a run command, especially a long one, and decode it to create a docker-compose file - this is a good tool for that

https://www.composerize.com/

thanks for the link… that will really helpfull

I’m also having issues to get a stack to start when trying to add the code.

keep getting error messages. I’m using ikoolcore and have Proxmox, Docker installed

no clue now how to get it to run or work.

I’m also a noob on these setups too and managed to get it to install and run on a Pi5 but unable too on this Ikoolcore

when you say path to the /config
how can this be done in Docker as I’m not using a Raspberry pi5?