Portainer - Easy Container Management
Portainer is a self-hosted service I was lucky enough to find early on in my docker journey. It is a container which helps you manage your other containers, and frankly, life would have been a lot more difficult without it.
Having said that, maybe you're fine with the Synology Docker GUI, or are a whiz on SSH and it suits your needs. But I love Portainer, and I love spreading the love.
In this article I'll take you through the steps to set it up, and give you a broad overview of the various tools you'll have available to you.
for any command starting withdocker
, to avoid permissions issues you either need to writesudo
before it, or you can follow this guide (scroll to point 6) to add your user to the docker group which means you will no longer need to addsudo
for permissions
Installing Portainer
First up, we need to create the container, and we'll use our trusty docker-compose for this:
- Login to your NAS via SSH and create your portainer network (skip this step if you just plan to use the default bridge network)
docker network create portainer
- In your file manager (either File Station or SMB via Windows 10 etc.) create your docker-compose.yml file, and copy paste the following:
services:
portainer: #container management
image: portainer/portainer-ce
container_name: portainer
volumes:
- $DOCKERDIR/portainer:/data
- /var/run/docker.sock:/var/run/docker.sock
environment:
- TZ=$TZ
ports:
- 9000:9000 #change before the ':' if necessary to avoid port conflicts
networks: #delete as necessary
- portainer
restart: unless-stopped
networks: # delete if you didn't create a portainer network
portainer:
external: true
- Create a file called
.env
in the same folder as your docker-compose.yml file and copy paste the following:
TZ=[your timezone e.g. 'Europe/Amsterdam']
DOCKERDIR=[/path/to/your/folder]
[ ]
brackets (and remove the brackets!) to match your system configyou do not need to use a .env and can pass that information directly via the docker-compose file, however I have gotten used to using one to keep sensitive data secure
- Regardless of the method you use to specify a folder for Portainer's
/data
mapping, make sure that you create that volume before moving on to the next step - Back in SSH, navigate to the directory you created your
docker-compose.yml
file, and run the following command:
docker-compose -p "portainer" up -d
-p "portainer"
part of the command will name your stack portainer
note that if you've named your stack, any further commands relating to this stack must also include the -p "portainer"
argument or it will create a new stack
If everything's gone well, you can now enter http://yourMachine'sIP:9000
in your browser address bar and you will be directed to this screen:

admin
as your username- Create a username (I've called mine 'myuser'), password, confirm the password, then hit 'Create user'
- At the next screen, make sure you select the 'Docker' button before hitting connect

/var/run/docker.sock
in our docker-compose filePortainer Configuration
On the next screen, you should see a dashboard-type view, which gives a broad overview of your current docker container numbers, plus some other stats like storage space used etc.

Select 'local':

All these options are now available for selection. Going into your 'Containers' section shows you a tabulated list of your containers, including their names, stack names, the images they use, and if set, their (clickable) port numbers for direct access to those services/gui.
You can also use portainer to create containers with docker-compose files. Click into the 'Stacks' tab:

You'll notice that my stacks here show as Limited
under 'Control'. This is because they weren't created using Portainer, rather via SSH. To create a stack via Portainer, click the '+ Add stack' button:

container_name: diun2
because I already have a diun containerI'm going to recreate my Diun container

Notice that I have variables listed as '$DOCKERDIR' and '$TZ' and '$APPTOKEN' - the compose file will look for this data in a .env file, which Portainer allows you to load from your local machine:

When you're ready, hit 'Deploy the stack'. You should get a green 'stack deployed successfully' notice on the top right corner of the screen, and you'll be redirected back to the 'Stacks' screen, where you should be able to select your new stack:

total
and it shows a user under 'Created'If you click into it, Â you'll have the option to modify, stop, start and delete the stack.
Let's go to the 'Containers' page and find the container:

Let's click the container name, and see what it shows us:

There's a lot of info here. At the top we have the actions (start, stop, remove etc.). Under the 'Status' parts, we can see the name (and change it if we want) and runtime. And under that, we have some other tools - 'Logs' and 'Console' are particularly useful.
'Console' allows you to ssh or 'bash' into your container should you have a need to make configurations or settings changes in that way
At the bottom of the page, we have the environment variables, the volumes being used, and the network options:

These network options are very handy for network joining/leaving.
There's a lot more you can do here, whether you use Portainer to create your stacks or not. You can prune (remove) unused images and volumes, create and manage networks, and of course have complete control over containers and stacks created via Portainer's GUI.
Enjoy!
Related Article


Have some feedback or something to add? Comments are welcome!
Please note comments should be respectful, and may be moderated