Install Portainer with Docker Compose

Install Portainer with Docker Compose
Photo by Ronan Furuta / Unsplash

In this post I will explain how to install Portainer with Docker Compose with nginx Proxy Manager.

Prerequisites:

  1. You've installed docker and docker compose on your system with this post.
  2. You've installed nginx Proxy Manager with docker compose like this.

Step 1: Create directory and docker-compose.yml file

mkdir /opt/containers/portainer

Create file:

sudo nano /opt/containers/portainer/docker-compose.yml
version: "3"

services:
  portainer:
    image: portainer/portainer-ce:latest
    container_name: portainer
    restart: always
    security_opt:
      - no-new-privileges:true
    ports:
      - '9443:9443'
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./portainer-data:/data

You might wonder why I don't have any networks in my docker-compose.yml file. This is the case because the networks highly depend on your past nginx Proxy Manager configuration. In my past post I explained how I've set up my NPM and for all future containers I will add all networks with portainer, which is much easier.

You can skip this if you don't use portainer, by adding the networks by yourself in the docker-compose.yml file. Keep in mind, that you should always add one external network for browser communication and one for communication with NPM itself for certificates. This is not really needed but recommended. You can also add external proxy hosts if they are not part of you internal network and/or even part of your current system environment.

Build and start the new docker container:

cd /opt/containers/portainer/
docker compose up -d

Step 2: Add networks to your containers

  1. Open up your browser of choice and access https://your-homeserver-ip:9443
  2. Create user account for portainer as the setup says
  3. Go to Home and open your local environment (default is local)
  4. Go to network and create the network npm-internal (if not already set up) check isolated network
  5. Create the external network npm-network
  6. Go to stack and open npm-proxy. Open npm-db and add the recently created network npm-internal-nw
  7. Again go to stack and open npm-proxy. Open npm-app and add the recently created networks npm-internal-nw and npm-network
  8. Go back to ssh cli: docker restart npm-app and npm-db
  9. In your Browser go to Portainer stack portainer and add to container network npm-network so that they are in the same network

Step 3: Add Portainer to NPM

  1. Access NPM via browser
  2. Add proxy host name of your choice. For me its portainer.home.pawnda.de pointing to https://portainer:9443
  3. Now you can access portainer via https://portainer.home.pawnda.de
  4. Don't forget to add the CNAME-record to your local dns to make this work

From now on you should add all new containers to the npm-network network to work with NPM and its domains with certificates. I also recommend to add all future containers with portainer.