Best Steps To Install Portainer on Centos 7 – OrcaCore

Posted on

Best Steps To Install Portainer on Centos 7 - OrcaCore

Best Steps To Install Portainer on Centos 7 – OrcaCore

This guide provides simple and easy steps to Install Portainer on Centos 7. The Portainer tool allows you to easily manage your docker containers from a web interface. It is a powerful GUI tool for those interested in managing their docker containers from a graphical interface. If you are searching for steps to install Portainer on Centos 7, this is the right place.

You can follow the steps below on the Orcacore website to set up your Portainer Docker GUI Tool on the Centos 7 server.

To get started and install Portainer on Centos 7, ensure you have the necessary prerequisites in place.

First, log in to your server as a root or non-root user with sudo privileges. For this purpose, you can follow this guide on Initial Server Setup with Centos 7.

To install Portainer, you must have Docker and Docker Compose installed on your server. To do these, you can check our Docker Tutorials to set it up:

How To Install and Use Docker on Centos 7

Install Docker Compose on Centos 7

When you are done with these requirements, follow the steps below to complete your Portainer installation.

Step 1 – Create a Docker Volume on Centos 7

In the first step, you must create a docker volume to store the Portainer data. To do this, you can use the following Docker command:

docker volume create data

Here we named it data, you can choose your desired name.

Then, use the following command to verify your Docker volume creation:

docker volume ls
**Output**
DRIVER    VOLUME NAME
local     data

Step 2 – Download Portainer Docker Image on Centos 7

At this point, you can easily use the following single command to download and run the Portainer Docker image on Centos 7:

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

When it is completed, you will get the following output:

**Output**
Unable to find image 'portainer/portainer:latest' locally
latest: Pulling from portainer/portainer
772227786281: Pull complete
96fd13befc87: Pull complete
0bad1d247b5b: Pull complete
b5d1b01b1d39: Pull complete
Digest: sha256:47b064434edf437badf7337e516e07f64477485c8ecc663ddabbe824b20c672d
Status: Downloaded newer image for portainer/portainer:latest
277d1cbc4823b6cb6921f3f9bf9df7b344a53e58291ab9d34e402d16917710b6

Step 3 – Check Portainer Status on Centos 7

To verify your Portainer installation, use the following command to check your Portainer status:

docker ps

In your output, you will see:

**Output**
CONTAINER ID   IMAGE                 COMMAND        CREATED              STATUS              PORTS                                                                                            NAMES
277d1cbc4823   portainer/portainer   "/portainer"   About a minute ago   Up About a minute   0.0.0.0:8000->8000/tcp, :::8000->8000/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp, 9443/tcp   portainer

Step 4 – Access Portainer Web GUI

At this point, you can access your Portainer through the Web interface by typing your server’s IP address in your web browser followed by 9000:

http://your-server-ip:9000

In the first screen of Portainer GUI, you should create the initial administrator user as shown below in the image:

[Image of Portainer administrator user]

Then, you will see your Portainer dashboard on Centos 7:

[Image of Portainer dashboard]

From your Portainer dashboard, you can click on each of the components to get more information regarding a specific component.

For more information, you can visit the Portainer Docs page.

Conclusion

At this point, you have learned that you can easily manage your Docker containers from a web interface by using an amazing tool named Portainer GUI tool. By installing Docker and Docker Compose you can easily set up your Portainer on Centos 7. Hope you enjoy it.

Alternative Solutions for Installing Portainer on CentOS 7

While the Docker run command is a quick and straightforward method, alternative approaches offer greater flexibility and control over the Portainer installation and management. Here are two different methods you can use to achieve the same goal of installing Portainer on Centos 7:

1. Using Docker Compose

Docker Compose provides a more declarative and manageable way to define and run multi-container Docker applications. Instead of a long docker run command, you define your services in a docker-compose.yml file. This file acts as a blueprint for your application, making it easier to reproduce, update, and share your setup.

Explanation:

Using Docker Compose provides several benefits:

  • Readability: The configuration is stored in a docker-compose.yml file, making it easier to understand the setup.
  • Maintainability: Changes to the configuration can be made in the docker-compose.yml file and applied with a single command.
  • Reproducibility: The docker-compose.yml file can be version-controlled, ensuring that the same setup can be easily reproduced across different environments.
  • Scalability: Docker Compose allows you to easily scale your application by increasing the number of containers for each service.

Steps:

  1. Create a docker-compose.yml file:

    Create a new file named docker-compose.yml in a suitable directory (e.g., /opt/portainer).

  2. Add the Portainer service definition:

    Add the following content to the docker-compose.yml file:

    version: "3.9"
    services:
      portainer:
        image: portainer/portainer-ce:latest
        container_name: portainer
        restart: always
        ports:
          - "8000:8000"
          - "9000:9000"
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - portainer_data:/data
    
    volumes:
      portainer_data:

    Explanation of the docker-compose.yml file:

    • version: "3.9": Specifies the version of the Docker Compose file format.
    • services:: Defines the services that make up the application. In this case, we have only one service: portainer.
    • portainer:: Defines the Portainer service.
      • image: portainer/portainer-ce:latest: Specifies the Docker image to use for the Portainer service. The portainer/portainer-ce image is the Community Edition, which is suitable for most use cases. :latest tag pulls the latest version of the image.
      • container_name: portainer: Sets the name of the container to portainer.
      • restart: always: Configures Docker to automatically restart the Portainer container if it stops.
      • ports:: Maps ports from the host machine to the container.
        • "8000:8000": Maps port 8000 on the host to port 8000 in the container (for the Portainer agent).
        • "9000:9000": Maps port 9000 on the host to port 9000 in the container (for the Portainer web UI).
      • volumes:: Mounts volumes into the container.
        • - /var/run/docker.sock:/var/run/docker.sock: Allows Portainer to interact with the Docker daemon on the host machine.
        • - portainer_data:/data: Mounts a named volume portainer_data to the /data directory in the container, where Portainer stores its data.
    • volumes:: Defines the named volume portainer_data. Docker Compose will automatically create this volume.
  3. Start Portainer using Docker Compose:

    Navigate to the directory containing the docker-compose.yml file (e.g., /opt/portainer) and run the following command:

    docker-compose up -d

    This command will:

    • up: Create and start the services defined in the docker-compose.yml file.
    • -d: Run the containers in detached mode (in the background).
  4. Verify the installation:

    Check the status of the Portainer container:

    docker ps

    You should see the Portainer container running.

  5. Access Portainer:

    Open your web browser and navigate to http://your-server-ip:9000 to access the Portainer web UI.

2. Using Systemd Service File

This method allows Portainer to be managed as a system service, automatically starting on boot and providing a standardized way to control its lifecycle (start, stop, restart). This approach integrates Portainer more deeply into the operating system.

Explanation:

Systemd is the system and service manager for Linux operating systems. Creating a systemd service file for Portainer offers the following advantages:

  • Automatic Startup: Portainer will automatically start when the server boots.
  • Centralized Management: You can manage Portainer using standard systemd commands (e.g., systemctl start portainer, systemctl stop portainer, systemctl restart portainer, systemctl status portainer).
  • Logging: Systemd handles logging for the Portainer container, making it easier to troubleshoot issues.

Steps:

  1. Create a systemd service file:

    Create a new file named portainer.service in the /etc/systemd/system/ directory:

    sudo nano /etc/systemd/system/portainer.service
  2. Add the service definition:

    Add the following content to the portainer.service file:

    [Unit]
    Description=Portainer CE Docker container
    Requires=docker.service
    After=docker.service
    
    [Service]
    Restart=always
    ExecStart=/usr/bin/docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
    ExecStop=/usr/bin/docker stop portainer
    ExecReload=/usr/bin/docker restart portainer
    
    [Install]
    WantedBy=multi-user.target

    Explanation of the portainer.service file:

    • [Unit]: Defines metadata and dependencies for the service.
      • Description: A human-readable description of the service.
      • Requires: Specifies that the docker.service must be running before Portainer can start.
      • After: Specifies that the docker.service should be started before Portainer.
    • [Service]: Defines the service execution parameters.
      • Restart: Specifies that the service should be restarted automatically if it fails. always means restart regardless of the exit code.
      • ExecStart: The command to execute to start the Portainer container. This is the same docker run command used in the original guide.
      • ExecStop: The command to execute to stop the Portainer container.
      • ExecReload: The command to execute to restart the Portainer container (used when reloading the service configuration).
    • [Install]: Defines how the service is installed and enabled.
      • WantedBy: Specifies that the service should be started when the system reaches the multi-user.target (i.e., the normal system operation mode).
  3. Reload systemd:

    Tell systemd to re-read the service files:

    sudo systemctl daemon-reload
  4. Enable and start the Portainer service:

    Enable the Portainer service to start on boot:

    sudo systemctl enable portainer.service

    Start the Portainer service:

    sudo systemctl start portainer.service
  5. Verify the installation:

    Check the status of the Portainer service:

    sudo systemctl status portainer.service

    You should see that the service is active and running.

  6. Access Portainer:

    Open your web browser and navigate to http://your-server-ip:9000 to access the Portainer web UI.

These alternative methods provide greater flexibility and control over your Portainer installation compared to the single docker run command. Docker Compose allows for declarative configuration and easier management of multi-container applications, while systemd integration provides automatic startup and centralized service management. Choose the method that best suits your needs and environment.