Skip to content

Portainer

Introduction

Portainer is a lightweight, open-source management UI for Docker environments. It provides an intuitive web interface for managing containers, images, volumes, and networks. In this tutorial, we'll guide you through the process of setting up Portainer on your Docker environment.

Prerequisites

  • Docker installed on your system (Windows, macOS, or Linux)
  • A web browser (e.g., Google Chrome, Mozilla Firefox)

Installation Steps

More details: Portainer

# Step 1: Pull the Portainer Image
#Open a terminal or command prompt and run the following command to pull the Portainer image from Docker Hub:
docker pull portainer/portainer-ce
#This command downloads the latest available version of Portainer.

#Step 2: Create a Volume for Portainer Data
#Create a Docker volume to store Portainer's data:
docker volume create portainer_data
#This volume will persist even if the Portainer container is deleted or updated.

#Step 3: Run the Portainer Container
#Run the Portainer container, mapping the portainer_data volume to the container's /data directory:
docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
  --restart=always \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v portainer_data:/data \
  portainer/portainer-ce

#If you want to stop it, you can run following command
docker stop portainer

#remove container and its data
docker rm portainer

docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:2.21.5

Here's a breakdown of the options used:

  • -d runs the container in detached mode
  • -p 8000:8000 maps port 8000 on the host to port 8000 in the container (for HTTP access)
  • -p 9443:9443 maps port 9443 on the host to port 9443 in the container (for HTTPS access)
  • --name portainer sets the name of the container to "portainer"
  • --restart=always flag ensures that the container will automatically restart if it exits or if the Docker daemon restarts. This is useful for maintaining high availability and minimizing downtime.
  • -v /var/run/docker.sock:/var/run/docker.sock mounts the Docker socket file, allowing Portainer to communicate with the Docker daemon
  • -v portainer_data:/data mounts the portainer_data volume to the container's /data directory

Access the Portainer Web Interface

Open a web browser and navigate to http://localhost:8000 (or https://localhost:9443 for HTTPS access). You'll see the Portainer login page.

Rollback Portainer Business Edition to CE

#1. Backup Your Data
# * Crucial Step: Before any downgrade, back up your Portainer data to prevent data loss.
# * Command (adjust to your container name):

docker run --rm --volumes-from portainer -v $(pwd):/backup ubuntu tar cvf /backup/backup.tar /data

#2. Downgrade the Database (if applicable)
# * Business to CE Downgrade: If you're downgrading from Portainer Business to Community Edition, you'll need to adjust the database.
# * Command (adjust to your data volume mount):

docker run -it --name portainer-database-rollback -v portainer_data:/data portainer/portainer-ee:latest --rollback-to-ce

#3. Stop and Remove the Existing Portainer Container
# * Command (adjust to your container name):

docker stop portainer
docker rm portainer

#4. Start a New Portainer Container with the Desired Version
# * Command (adjust to the desired version):

docker run -d -p 9443:9443 -p 8000:8000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:<version>

#* Replace <version> with the specific Portainer CE version you want to downgrade to.
The content provided is generated with the help of artificial intelligence (AI) and may contain inaccuracies or outdated information due to the limitations of AI. While I strive to review and validate the content, some errors or inaccuracies may still be present in the final output. Please use this content as a general guide only and verify any critical information through reputable sources before relying on it. I appreciate your understanding and feedback in helping us improve the accuracy and quality of our AI-generated content."