How to Install Portainer in Linux CentOS 8

Posted on

Introduction

This is an article where the main focus is about how to install portainer in a virtual server. The virtual server itself is running in a VirtualBox application. It is a virtual server running using Linux CentOS 8 as the operating system. Actually, this article is the continuation from the other article. The other article is an article with the title of ‘How to Install Docker in Linux CentOS 8’ in this link. That article is focusing on how to install Docker in Linux CentOS 8. On the other hand, this article will follow up on installing Portainer. The reference for portainer installation is also the same. It is from an article with the title of ‘Install Docker and Manage it with Portainer on CENTOS 8 / RHEL 8’ in this link.

Portainer Step Installation

The installation of portainer exist in the following sequences :

  1. First of all, just pull the images of portainer by executing the following command :

    docker pull portainer/portainer
    

    The output execution of the above command exist as follows :

    [root@10 ~]# docker pull portainer/portainer
    Using default tag: latest
    latest: Pulling from portainer/portainer
    94cfa856b2b1: Pull complete
    49d59ee0881a: Pull complete
    a2300fd28637: Pull complete
    Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f
    Status: Downloaded newer image for portainer/portainer:latest
    docker.io/portainer/portainer:latest
    [root@10 ~]#
    
  2. Next, after successfully downloading the portainer image, just run it. The following command is a command for running portainer using docker tool :

    docker run -d -p 9000:9000 --name your_portainer_name --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer
    

    After executing the above command, it is running but it ends in failure. Soon after, just execute the command again but changing the name of the portanner as follows :

    docker run -d -p 9000:9000 --name my_portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer
    
    [root@10 ~]# docker run -d -p 9000:9000 --name your_portainer_name --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer
    ^C
    [root@10 ~]#
    

    Apparently, the Ctrl+C command execution above is actually cancelling the progress for running the portainer. Canceling it is according to an assumption. The assumption is figuring that there is something wrong with the execution. But in the end it just the process taking it too long. So, after executing it again by changing the name or the label of the portainer, it is actually a success as follow :

    [root@10 ~]# docker run -d -p 9000:9000 --name my_portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /opt/portainer:/data portainer/portainer
    813e79d4eaeaa4e7142d6497edbb1bdd188dd665401375d5c8b2c9637c0d6dd7
    [root@10 ~]#
  3. Soon after the successful command execution above, just list the available container. It is useful to check whether the container exist or not from the previous execution. It will list the available container maintaining and running by docker, execute the following command :

    [root@10 ~]# docker ps
    CONTAINER ID   IMAGE                 COMMAND        CREATED          STATUS          PORTS                    NAMES
    813e79d4eaea   portainer/portainer   "/portainer"   23 seconds ago   Up 21 seconds   0.0.0.0:9000->9000/tcp   my_portainer
    [root@10 ~]#
    
  4. Furthermore, in order to access the running container providing portainer service in port 9000, do not forget to add in the firewall rules as follows :
    [root@10 ~]# firewall-cmd --permanent --add-port=9000/tcp
    success
    [root@10 ~]# firewall-cmd --reload
    success
    [root@10 ~]#
    
  5. How to Install Portainer in Linux CentOS 8
    How to Install Portainer in Linux CentOS 8

    The following is just an action for accessing the portainer. Since the portainer is running in a virtual server exist in a VirtualBox application, it need a rule for accessing it. In this context, accessing portainer from host machine to a guest machine need a simple rule for an alternative. It is a port forwarding rule from a host machine to port 9000 running in the guest machine utilized by portainer. The following is the display of the portainer :

    Why is the image above is accessing localhost with a port of 8000 instead of the IP Address of the guest machine with a port of 9000 ?. The answer is because of the rule of port forwarding. The following is the definition of that port forwarding rule :

    How to Install Portainer in Linux CentOS 8
    How to Install Portainer in Linux CentOS 8

    Normally, accessing the portainer service running in a local machine will be http://localhost:9000. Since the access is from a host machine to a portainer service running in a guest machine with the above rule port forwarding will be http://localhost:8000. The host machine listens in port 8000 and then forward any incoming requests in the host machine to the port 9000 running in the guest machine.

2 thoughts on “How to Install Portainer in Linux CentOS 8

Leave a Reply