Portainer is an open-source tool designed to simplify container management and deployment. It provides a user-friendly web interface that allows users to easily manage Docker, Docker Swarm, Kubernetes, and ACI (Azure Container Instances) environments.

You might want to use Portainer to manage your container applications instead of the native Container Station provided by QNAP.

Install Portainer On QNAP

The only way to run Portainer on your QNAP is to use Container Station to run the Portainer docker-compose.yml file, and it worked very well.

I’ve already covered how to run docker-compose.yml files in Container Station here , you won’t need to mess around with UID and GID values for the Portainer install. Create a new Container Station application and place the following code and hit run.

Make sure the volume location /share/dockerapps/portainer exists or create at another prefered location.

version: '3.3'
services:
portainer:
image: portainer/portainer-ce:latest
ports:
- "9000:9000"
- "8000:8000" # Optional, for Edge agent communication
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/share/dockerapps/portainer:/data"
restart: always

Once you start the application head over to http://<your-qnap-ip-address&gt;:9000 and finish your setup by selecting an admin password.

What Container Station calls ‘Apps’ are called ‘Stacks’ in Portainer.

I have moved all of my Postgresql container applications to Portainer to take advantage of better container management, in this case I was able to use docker networking to connect two database containers to the pgadmin container. I will provide the docker-compose.yml files in a bit.

You will notice that Portiainer detects its own container stack called ‘portainer’ and helpfully limits your management access preventing your from destroying the portainer container by using the portainer container.

You will also notice that container station does the reverse.

Container Station will list all of your portainer applications but will remind you that the application was created outside of Container Station and that you can’t manage your application inside CS. The ‘portainer’ application though is manageable and you might want to upgrade the docker image when new versions are available.

The file share permissions, GID and UID advice we went over in https://rexbytes.com/2023/12/11/qnap-container-station-docker-setup-postgres/ still applies to ‘stacks’/’Applications’ created in Portainer.

I use Portainer for all my container management on QNAP.

Stack Multiple Postgres Containers With One pgAdmin4 Container

I needed to seperate my play area from the more stable data I work with. To do this I decided to create a postgres container for work, and another postgres container for play. I also then connected a pgAdmin container to both. To do this I needed to use docker networking which didn’t play well in Container Station which is why I looked in to Portainer.

Note that the shares/volumes are organised differently but the permission and GID and UID steps are the same as in the previous linked article.

Here are the docker-compose.yml files I used.

Play Database Container

version: '3'
services:
postgres:
image: postgres:16.2
restart: unless-stopped
ports:
- 0.0.0.0:5432:5432
volumes:
- /share/dockerapps/databases/postgresql/data:/var/lib/postgresql/data
- /share/dockerapps/databases/postgresql/wal:/var/lib/postgresql/wal

environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- PGID=100
- PUID=1003
- POSTGRES_HOST_AUTH_METHOD=scram-sha-256
- POSTGRES_INITDB_ARGS=--data-checksums
- POSTGRES_INITDB_WALDIR=/var/lib/postgresql/wal
- POSTGRES_SSL_CERT_FILE=/var/lib/postgresql/data/server.crt
- POSTGRES_SSL_KEY_FILE=/var/lib/postgresql/data/server.key
- POSTGRES_SSL_CA_FILE=/var/lib/postgresql/data/ca.crt
networks:
- pgadmin4_databasenetwork

networks:
pgadmin4_databasenetwork:
external: true

Work Database Container

Note that the default external postgres port 5432 was taken by the above docker-compose.yml file, and that in the following file the port has been incremented to 5433.

version: '3'
services:
workpostgres:
image: postgres:16.2
restart: unless-stopped
ports:
- 0.0.0.0:5433:5432
volumes:
- /share/dockerapps/databases/workpostgresql/data:/var/lib/postgresql/data
- /share/dockerapps/databases/workpostgresql/wal:/var/lib/postgresql/wal

environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- PGID=100
- PUID=1003
- POSTGRES_HOST_AUTH_METHOD=scram-sha-256
- POSTGRES_INITDB_ARGS=--data-checksums
- POSTGRES_INITDB_WALDIR=/var/lib/postgresql/wal
- POSTGRES_SSL_CERT_FILE=/var/lib/postgresql/data/server.crt
- POSTGRES_SSL_KEY_FILE=/var/lib/postgresql/data/server.key
- POSTGRES_SSL_CA_FILE=/var/lib/postgresql/data/ca.crt
networks:
- pgadmin4_databasenetwork

networks:
pgadmin4_databasenetwork:
external: true

pgAdmin Container

This docker-file is responsible for creating the docker network ‘databasenetwork‘ which is connected to by the database docker-files using the network name ‘pgadmin4_databasenetwork‘, the pgadmin4 part of this network string name is taken from the stack name (see above portainer screenshot) not the service name in the following.

version: '3'
services:
pgadmin4:
image: dpage/pgadmin4:8.3
restart: unless-stopped
ports:
- "5050:80"
environment:
- [email protected]
- PGADMIN_DEFAULT_PASSWORD=password
- PGID=100
- PUID=1003
volumes:
- /share/dockerapps/databases/pgadmin4:/var/lib/pgadmin
networks:
- databasenetwork

networks:
databasenetwork:
driver: bridge

GitHub Files


https://github.com/RexBytes/qnap-portainer-postgres
0 forks.
0 stars.
0 open issues.

Recent commits:

Leave a Reply