How to install Portainer on Ubuntu

To get Portainer up and running on your Ubuntu system, you'll need to follow a few straightforward steps. Portainer is a tool that helps you manage Docker containers more easily, and we'll be setting up the Community Edition (CE) here.
First things first, make sure you have Docker installed on your Ubuntu machine. If you haven't installed it yet, follow the instructions in How to install Docker on Ubuntu.
You'll also need sudo access on the machine where you're installing Portainer. This is because you'll be running commands that require administrative privileges.
Portainer uses two parts: the Portainer Server and the Portainer Agent. We're going to focus on installing the Portainer Server for now. By default, it will use port 9443 for its user interface and port 8000 for a TCP tunnel server, which is only needed if you plan to use the Edge compute features.
Before you start, there are a few things to keep in mind about your setup:
- Your system should meet the requirements listed in Portainer's documentation. While it might work with different setups, you might need to tweak some settings or deal with limited functionality.
- You'll be accessing Docker through Unix sockets, but you could also use TCP if you prefer.
- SELinux should be turned off on your Docker machine. If you need SELinux, you'll have to add the
--privileged
flag when you start Portainer. - Docker should be running as root. If you're using rootless Docker, there are some limitations and extra steps you'll need to take.
Okay, let's get started with the installation.
- Create a Docker Volume for Portainer Data
You'll need to create a volume where Portainer can store its data. Open your terminal and run:docker volume create portainer_data
This command creates a volume namedportainer_data
that Portainer will use to keep its database. - Download and Install the Portainer Server Container
Now, you'll download and start the Portainer Server container. In your terminal, run: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
This command does a few things:-d
runs the container in the background.-p 8000:8000
and-p 9443:9443
map the container's ports to your host machine.--name portainer
names your container for easy reference.--restart=always
ensures the container restarts if your system reboots.-v /var/run/docker.sock:/var/run/docker.sock
gives Portainer access to your Docker daemon.-v portainer_data:/data
mounts the volume you created earlier to store Portainer's data.portainer/portainer-ce:2.21.5
is the specific version of Portainer you're installing.
Portainer comes with a self-signed SSL certificate for port 9443 by default. If you want to use your own SSL certificate, you can set it up either during installation or through the Portainer UI after installation.
If you need to use the legacy HTTP port 9000, you can add-p 9000:9000
to thedocker run
command. - Check if Portainer is Running
To make sure Portainer started correctly, you can list your running Docker containers with:docker ps
You should see an entry for the Portainer container, showing it's up and running. - Access Portainer
Now that Portainer is installed, you can access it by opening a web browser and navigating tohttps://localhost:9443
. If you're accessing it from another machine, replacelocalhost
with the IP address or domain name of your Ubuntu server.
You'll be greeted with the initial setup page for Portainer Server, where you can finish setting up your Portainer environment.
That's it! You've successfully installed Portainer on your Ubuntu system. From here, you can start managing your Docker containers with ease.