Installing Portainer on the Raspberry Pi

 

Portainer is a lightweight management UI for Docker that simplifies the process of managing Docker containers. It offers an intuitive web interface to deploy, configure, and monitor containers. This guide walks you through installing and setting up Portainer on a Raspberry Pi, allowing you to manage Docker containers with ease.


What You Will Need

  1. Raspberry Pi (any model with Docker support, e.g., Pi 3, Pi 4)
  2. Raspberry Pi OS installed on your Raspberry Pi
  3. Internet connection for downloading Portainer
  4. Docker installed on your Raspberry Pi (Portainer requires Docker to run)

Step 1: Install Docker on the Raspberry Pi

If Docker is not already installed on your Raspberry Pi, follow these steps to install it:

  1. Update the package list:

    sudo apt update
    sudo apt upgrade -y
    
  2. Install Docker using the official script:

    curl -sSL https://get.docker.com | sh
    
  3. After installation, add the current user to the Docker group to allow running Docker commands without sudo:

    sudo usermod -aG docker ${USER}
    
  4. Reboot the Raspberry Pi to apply the changes:

    sudo reboot
    
  5. Verify that Docker is installed correctly:

    docker --version
    

Step 2: Install Portainer

Now that Docker is installed, you can install Portainer as a Docker container.

  1. Pull the Portainer image from Docker Hub:

    docker pull portainer/portainer-ce
    
  2. Create and run a Portainer container:

    docker volume create portainer_data
    docker run -d -p 9000:9000 -p 9443:9443 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
    

    Here's what the command does:

    • -d: Run the container in detached mode.
    • -p 9000:9000: Expose the web UI on port 9000.
    • -p 9443:9443: Expose the web UI with HTTPS on port 9443.
    • --name portainer: Set the container name as "portainer".
    • --restart always: Automatically restart Portainer on boot or if the container crashes.
    • -v /var/run/docker.sock:/var/run/docker.sock: Bind mount Docker socket for managing Docker containers.
    • -v portainer_data:/data: Mount a volume to persist Portainer data.
  3. Wait for Portainer to start, then open your web browser and go to:

    http://<raspberry_pi_ip>:9000
    

    Replace <raspberry_pi_ip> with your Raspberry Pi’s IP address.


Step 3: Set Up Portainer

When you first access the Portainer web interface, you’ll be prompted to create an administrator account.

  1. Create an Admin Account:

    • Set a username and password for the admin account.
    • Click "Create User" to proceed.
  2. Connect to Docker:

    • Choose Local to manage the local Docker environment on your Raspberry Pi.
    • Click Connect.

Step 4: Using Portainer

Once connected, you'll be taken to the Portainer dashboard, where you can start managing your Docker containers. You can:

  • View Running Containers: Monitor the status of all active containers.
  • Deploy New Containers: Create new Docker containers from the Portainer interface.
  • Manage Volumes and Networks: View and configure Docker volumes and networks.
  • View Logs and Stats: Monitor the logs and stats of running containers.

Step 5: Managing Portainer

  1. Accessing Portainer Remotely:

    • To securely access Portainer remotely, you can configure SSL using a reverse proxy (e.g., Nginx or Traefik) or use port 9443 for HTTPS (enabled by the docker run command above).
  2. Stop and Restart Portainer: To stop Portainer, run:

    docker stop portainer
    

    To restart Portainer, run:

    docker restart portainer
    
  3. Removing Portainer: If you want to remove Portainer, stop and remove the container:

    docker stop portainer
    docker rm portainer
    

    Optionally, you can also remove the Docker volume:

    docker volume rm portainer_data
    

Troubleshooting

  • Portainer Not Accessible: Ensure that your Raspberry Pi’s firewall allows access to ports 9000 and 9443. If using HTTPS, verify that SSL certificates are set up correctly.
  • Docker Container Crashing: Check the container logs for errors:
    docker logs portainer
    
  • No Docker Access: Make sure your user is part of the Docker group:
    sudo usermod -aG docker ${USER}
    sudo reboot
    

Conclusion

Portainer simplifies Docker container management on the Raspberry Pi by providing an easy-to-use web interface. With just a few commands, you can get up and running with Docker and Portainer, making it easier to manage and monitor your containers. Whether you're running home automation systems, web servers, or other Dockerized services, Portainer is an invaluable tool for managing your Raspberry Pi's Docker environment.


Leave a comment

Notice an Issue? Have a Suggestion?
If you encounter a problem or have an idea for a new feature, let us know! Report a problem or request a feature here.