Comments

Latest Posts

Portainer Usage Tips and Tricks

Portainer is my favorite docker management tool, actually only one I used. If you have better one, please let me know. This post is to summarize some usage during playing with application.
[Updated on Mar 6 2021]
Some related posts:


Install Docker and Portainer

By default, Portainer store its data inside the container in the /data folder on Linux (C:\\data on Windows).
You’ll need to persist Portainer data to keep your changes after restart/upgrade of the Portainer container.  Docker Deploy document: https://portainer.readthedocs.io/en/latest/deployment.html . You can use a bind mount on Linux to persist the data on the Docker host folder:

1  Install Docker. For other linux release, commands can be found here.
#For Ubuntu 20.04 version
#Ubuntu 20.04
sudo apt install docker.io
sudo apt install docker-compose

Or Other Linux Versions:
#CentOS 7, Debian, Ubuntu 18.04/16.04
curl -sSL https://get.docker.com/ | sh 
systemctl start docker 
systemctl enable docker
For Docker Compose installation:
note: Check the latest version of docker-compose from https://docs.docker.com/compose/release-notes/
sudo curl -L "https://github.com/docker/compose/releases/download/1.28.6/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Or

curl -L "https://get.daocloud.io/docker/compose/releases/download/1.28.6/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Check version:

[[email protected] ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:33:55 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:32:17 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

[[email protected] ~]# curl -L "https://get.daocloud.io/docker/compose/releases/download/1.28.6/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   379  100   379    0     0    140      0  0:00:02  0:00:02 --:--:--   140
100   633  100   633    0     0    217      0  0:00:02  0:00:02 --:--:--  7112
100 11.6M  100 11.6M    0     0  3178k      0  0:00:03  0:00:03 --:--:-- 3178k
[[email protected] ~]# chmod +x /usr/local/bin/docker-compose
[[email protected] ~]# docker-compose version
docker-compose version 1.28.6, build 5db8d86f
docker-py version: 4.4.4
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019



2  Install Portainer

[email protected]:/# docker volume create portainer_data
[email protected]:/# docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
[email protected]:/# which docker
[email protected]:/# find . -type d -name "portainer_data"
./var/lib/docker/volumes/portainer_data

or in CentOS:
[[email protected] ~]# find / -type d -name "portainer_data"
/var/lib/docker/volumes/portainer_data


You can try out the public demo instance: http://demo.portainer.io/ (login with the username admin and the password tryportainer).

Update Portainer

1. Update image 

1.1 Older version upgrade to 2.0 

Old portainer/portainer repository is the home of v1.24.x, which has been deprecated. All new releases for Portainer 2.0 will be published in portainer/portainer-ce

[email protected]:/# docker stop portainer
portainer
[email protected]:/# docker rm portainer

If you only do start portainer, it won't use the latest image to start. You will have to remove old version container, then create a new portainer with downloaded new image.

[email protected]:/# docker pull portainer/portainer-ce:latest
portainer


If you could not find image, just use command "docker search portainer-ce"

[[email protected] ~]# docker search portainer-ce
NAME                           DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
portainer/portainer            This Repo is now deprecated, use portainer/p…   2033
portainer/portainer-ce         Portainer CE - Making Docker and Kubernetes …   398
thibaudlabat/portainer_32      Portainer built for 32bit Linux [ OUTDATED ]…   1
thibaudlabat/portainer-ce-32   32-bit / x86 portainer-ce                       0
terryromeu3sr/portainer-ce                                                     0
luomoxu/portainer-ce-cn                                                        0
nativeit/portainer-ce                                                          0
6053537/portainer-ce                                                           0
hanlahanla/portainer-ce                                                        0

Or:
 docker service update --image portainer/portainer-ce:latest portainer

1.2 Upgrade to latest (Current Version is higher 2.0)

A little bit change from above commands, using id to replace docker name in the commands. 

[email protected]:~# docker ps -a | grep portainer
ea61e3109076   portainer/portainer-ce:latest   "/portainer"             19 months ago   Up 4 weeks             8000/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp                                                                                          hp-tc-portainer
[email protected]:~# docker stop ea61e3109076
ea61e3109076
[email protected]:~# docker rm ea61e3109076
ea61e3109076
[email protected]:~# docker pull portainer/portainer-ce:latest
latest: Pulling from portainer/portainer-ce
772227786281: Pull complete
96fd13befc87: Pull complete
0bad1d247b5b: Pull complete
b5d1b01b1d39: Pull complete
Digest: sha256:f7607310051ee21f58f99d7b7f7878a6a49d4850422d88a31f8c61c248bbc3a4
Status: Downloaded newer image for portainer/portainer-ce:latest
docker.io/portainer/portainer-ce:latest
[email protected]:~# docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
f9a7d0df8e2e38d01c9d572236dc8dcb2d3bf21444311b1a0fbf0e7053a8bdb9
[email protected]:~# docker image ls
REPOSITORY               TAG       IMAGE ID       CREATED         SIZE
portainer/portainer-ce   latest    5f11582196a4   2 months ago    287MB
openspeedtest/latest     latest    98b90897430c   19 months ago   55.6MB
portainer/portainer-ce   <none>    8bd64518b976   19 months ago   210MB
pihole/pihole            latest    257fd58747c5   21 months ago   335MB
luodaoyi/kms-server      latest    3ed72d142784   24 months ago   5.74MB
[email protected]:~# docker image rm 8bd64518b976
Untagged: portainer/[email protected]:79edf1302c9b4fdb06bc23321cc551e9118c29e6d668e12e23d4e58d993ab830
Deleted: sha256:8bd64518b97697ed2d0d00b5dfd46260f729cdb5ae8120b38e404a05ad08f61b
Deleted: sha256:552b482deea1a69a4e787000b4a92348d8d46b820cfa7795cd1039db1f9183d3
Deleted: sha256:0f434987961209eca0504583fba181d92a59aa39c5b76f6e82a00a932cda1c38
Deleted: sha256:2365c13d7baf5be2ddb9f13ac4884996d67d7aa93b2b1ae6cccfd80b8a509415
[email protected]:~# docker image ls
REPOSITORY               TAG       IMAGE ID       CREATED         SIZE
portainer/portainer-ce   latest    5f11582196a4   2 months ago    287MB
openspeedtest/latest     latest    98b90897430c   19 months ago   55.6MB
pihole/pihole            latest    257fd58747c5   21 months ago   335MB
luodaoyi/kms-server      latest    3ed72d142784   24 months ago   5.74MB
[email protected]:~#


2. Start Container with new image



[[email protected] ~]# docker run -d -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
Unable to find image 'portainer/portainer-ce:latest' locally
latest: Pulling from portainer/portainer-ce
94cfa856b2b1: Pull complete
49d59ee0881a: Pull complete
527b866940d5: Pull complete
Digest: sha256:5064d8414091c175c55ef6f8744da1210819388c2136273b4607a629b7d93358
Status: Downloaded newer image for portainer/portainer-ce:latest
90212707d5a674ef3ba23588f25b014cea60b25e0f1826ed06e09ec568930b0a




3. Delete old image

Docker image ls
docker image rm <Repository name>

[email protected]:~# docker image ls
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
portainer/portainer-ce   latest              96a1c6cc3d15        4 weeks ago         209MB
portainer/portainer      latest              62771b0b9b09        7 months ago        79.1MB
nginx                    latest              e791337790a6        10 months ago       127MB
[email protected]:~# docker image rm portainer/portainer
Untagged: portainer/portainer:latest
Untagged: portainer/[email protected]:f8c2b0a9ca640edf508a8a0830cf1963a1e0d2fd9936a64104b3f658e120b868
Deleted: sha256:62771b0b9b0973a3e8e95595534a1240d8cfd968d30ec82dc0393ce0a256c5f3
Deleted: sha256:c291f08e07bbfde10ee7ae7a9c618ebedc5e5c4b3ab494b0636fb260e2a20717
Deleted: sha256:dd4969f97241b9aefe2a70f560ce399ee9fa0354301c9aef841082ad52161ec5
[email protected]:~# docker image ls
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
portainer/portainer-ce   latest              96a1c6cc3d15        4 weeks ago         209MB
nginx                    latest              e791337790a6        10 months ago       127MB


YouTube Video:



A useful command to get rid of the stopped containers:
  • docker rm `docker ps -a -q`

Check Containers



[email protected]:/# docker container ls -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
a9ea9891aa03        nginx:latest        "nginx -g 'daemon of…"   4 weeks ago         Up 4 weeks          0.0.0.0:80->80/tcp       nginx1
4cf95554b471        4cda95efb0e4        "/portainer"             4 weeks ago         Up 11 minutes       0.0.0.0:9000->9000/tcp   portainer


[email protected]:/# docker stats
CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
a9ea9891aa03        nginx1              0.00%               3.172MiB / 982.2MiB   0.32%               64.1MB / 132MB      14.6MB / 0B         3
4cf95554b471        portainer           0.01%               11.3MiB / 982.2MiB    1.15%               4.55MB / 50.2MB     90.7MB / 238MB      10


Log into Container

[[email protected] ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                    NAMES
26a4cc3a312a        nginx:latest          "nginx -g 'daemon of…"   24 hours ago        Up 16 minutes       0.0.0.0:80->80/tcp       portainer-nginx1
d5c3f33bd8ee        portainer/portainer   "/portainer"             25 hours ago        Up 25 hours         0.0.0.0:9000->9000/tcp   portainer
[[email protected] ~]#

[[email protected]centos1docker ~]# docker exec -it portainer-nginx1 /bin/bash
[email protected]26a4cc3a312a:/#
[email protected]26a4cc3a312a:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
[email protected]26a4cc3a312a:/# uname -a
Linux 26a4cc3a312a 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64 GNU/Linux

Install Network Utilities in Container

Most of times, the docker image is not including following network utilities which can help you troubleshooting your network connectivity, such as ping, ifconfig, tracert, telnet etc. You might want to install them for yourself.

[email protected]:/# apt-get update
[email protected]:/# apt-get install iputils-ping
[email protected]:/# apt-get install telnet
[email protected]:/# apt-get install traceroute
[email protected]:/# apt-get install net-tools

Note: net-tools will include ifconfig / netstat commands

Reset Portainer Admin Password

Note: https://documentation.portainer.io/v2.0/users/reset-admin/

[[email protected] ~]# docker ps
CONTAINER ID        IMAGE                        COMMAND             CREATED             STATUS              PORTS                         NAMES
f554ef7dd8ed        portainer/portainer:latest   "/portainer"        9 months ago        Up 6 months         0.0.0.0:9000->9000/tcp        portainer
[[email protected] ~]#
[[email protected] ~]# docker stop portainer
portainer
[[email protected] ~]# docker run --rm -v portainer_data:/data portainer/helper-reset-password
Unable to find image 'portainer/helper-reset-password:latest' locally
latest: Pulling from portainer/helper-reset-password
79916c70cb9e: Pull complete
93e26fa95550: Pull complete
Digest: sha256:735a809b1bfe14b5fae340d4b350bae97c2016371c47fb6e34d71a45e4512f79
Status: Downloaded newer image for portainer/helper-reset-password:latest
2021/04/20 13:31:09 Password succesfully updated for user: admin
2021/04/20 13:31:09 Use the following password to login: ]{1og%[email protected]"70l469M!yxSOi+?53Yb
[[email protected] ~]# docker start portainer
portainer


Now you should be able to log in usign admin account with generated password.



Custom Bridge Network


Create a new bridge network to join your Containers into same network. In this way, they can access it through their name directly.





Get your Docker Container to join into your new created bridge network.

In this way, we can directly use container's name to access each other. 



No comments