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.
  • Install Docker and Portainer
  • Update Portainer
  • Check Containers
  • Log into Container
  • Install Network Utilities in Container
[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

Check version:

[root@localhost ~]# 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

[root@localhost ~]# 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
[root@localhost ~]# chmod +x /usr/local/bin/docker-compose
[root@localhost ~]# 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

root@Ubuntu18:/# docker volume create portainer_data
root@Ubuntu18:/# 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
root@Ubuntu18:/# which docker
root@Ubuntu18:/# find . -type d -name "portainer_data"
./var/lib/docker/volumes/portainer_data

or in CentOS:
[root@centos-nextcloud-aria2 ~]# 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

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
root@Ubuntu18:/# docker stop portainer
portainer
root@Ubuntu18:/# 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.
root@Ubuntu18:/# docker start portainer
portainer

some os, you might need to use command "docker pull docker.io/portainer/portainer-ce"

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


[root@centos7-docker-portainer ~]# 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
2. Start Container with new image


[root@centos7-docker-portainer ~]# 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>



root@opc-ubuntu-docker:~# 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
root@opc-ubuntu-docker:~# docker image rm portainer/portainer
Untagged: portainer/portainer:latest
Untagged: portainer/portainer@sha256:f8c2b0a9ca640edf508a8a0830cf1963a1e0d2fd9936a64104b3f658e120b868
Deleted: sha256:62771b0b9b0973a3e8e95595534a1240d8cfd968d30ec82dc0393ce0a256c5f3
Deleted: sha256:c291f08e07bbfde10ee7ae7a9c618ebedc5e5c4b3ab494b0636fb260e2a20717
Deleted: sha256:dd4969f97241b9aefe2a70f560ce399ee9fa0354301c9aef841082ad52161ec5
root@opc-ubuntu-docker:~# 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



root@Ubuntu18:/# 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


root@Ubuntu18:/# 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

[root@centos1docker ~]# 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
[root@centos1docker ~]#

[root@centos1docker ~]# docker exec -it portainer-nginx1 /bin/bash
root@26a4cc3a312a:/#
root@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/"
root@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.

root@26a4cc3a312a:/# apt-get update
root@26a4cc3a312a:/# apt-get install iputils-ping
root@26a4cc3a312a:/# apt-get install telnet
root@26a4cc3a312a:/# apt-get install traceroute
root@26a4cc3a312a:/# apt-get install net-tools

Note: net-tools will include ifconfig / netstat commands









No comments