Portainer provides a web-based interface for managing Docker containers, images, networks, and volumes, making it easier to manage your Docker environment.
Portainer simplifies the management of Docker resources, providing a user-friendly graphical interface for container management, deployment, and monitoring.
To install Portainer on your system, follow these steps. Portainer provides a web-based interface for managing Docker containers, images, networks, and volumes, making it easier to manage your Docker environment.
Step-by-Step Installation of Portainer
Prerequisites:
- Docker: Ensure Docker is already installed on your system.
- If Docker is not installed, you can install it using the following commands for Ubuntu 22.04:
sudo apt update sudo apt install -y ca-certificates curl gnupg lsb-release # Add Docker’s official GPG key sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg # Set up the Docker repository echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # Install Docker Engine sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin # Verify Docker installation sudo systemctl start docker sudo systemctl enable docker docker --version
Now that Docker is installed, you can proceed with installing Portainer.
Step 1: Create a Docker Volume for Portainer Data
Portainer stores all its data (such as configurations, templates, etc.) in a Docker volume. Run the following command to create a volume:
docker volume create portainer_data
Step 2: Install Portainer
Use the Docker command to install Portainer as a container. Portainer provides both a Community Edition (CE) and a Business Edition (BE). Here we’ll install the Portainer Community Edition (CE).
-
Run the Portainer container:
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:latest
- The
-p 9000:9000
option maps Portainer’s web UI to port 9000 on your host. - The
-p 9443:9443
option maps the HTTPS port for secure access to 9443. - The
-v /var/run/docker.sock:/var/run/docker.sock
option allows Portainer to interact with the Docker engine. - The
-v portainer_data:/data
option ensures Portainer’s data is stored persistently in the Docker volume.
- The
-
Wait for the container to start: You can check the status of the container by running:
docker ps
You should see Portainer listed with the ports
9000
and9443
exposed.
Step 3: Access Portainer Web UI
Once Portainer is running, access it via a web browser by navigating to:
- **http://
:9000** for HTTP access. - **https://
:9443** for HTTPS access.
Step 4: Initialize Portainer
-
Set up the admin user: When you access Portainer for the first time, you’ll be prompted to create an admin user. Provide a username and a secure password.
-
Choose Docker Environment: After logging in, you’ll be asked to choose the environment you want to manage. Select Docker and proceed. This will set Portainer to manage the local Docker instance.
Step 5: Manage Your Docker Environment with Portainer
Now that Portainer is set up, you can use it to:
- Manage Docker containers, images, networks, and volumes.
- Deploy stacks and containers using Docker Compose.
- Monitor container statistics and resource usage.
- Set up and manage users and access control.
You can log into Portainer at any time by navigating to http://<your-server-ip>:9000
or https://<your-server-ip>:9443
.
Optional: Enabling HTTPS (for production use)
To enable secure HTTPS access in a production environment, follow these additional steps:
- Obtain an SSL certificate, either from Let’s Encrypt or your preferred certificate authority.
-
Modify the Portainer command to include SSL certificate paths:
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 \ -v /path/to/cert.pem:/certs/cert.pem \ -v /path/to/key.pem:/certs/key.pem \ portainer/portainer-ce:latest \ --ssl --sslcert /certs/cert.pem --sslkey /certs/key.pem
Now, you’ll be able to securely access Portainer using HTTPS.