Portainer is a container management tool that seamlessly works with both Docker and Kubernetes.
It is available in two versions:
free and open Community Edition;
paid Business Edition with additional features for corporate clients.
In this article, we will focus on installing Portainer on Ubuntu 22.04 with Docker and using the Community Edition. Although we will use Ubuntu as an example, most of the steps are similar for other operating systems, making this tutorial applicable to a variety of use cases.
Portainer is excellent for both beginners and professionals. Its intuitive graphical interface greatly simplifies management, making container technology accessible even to those new to the field. Experienced users will also find a rich selection of options for fine-tuning and personalization.
The article will focus on installing, overviewing the main functions and settings, connecting an external server as an environment, and providing a practical example of deploying WordPress on an external server using Portainer.
A computer or a cloud server running a Linux-based OS such as Ubuntu, Debian etc.
In this article, we'll demonstrate installing Portainer on a local machine; however, if you plan to use it as a team, the application can also be installed on a cloud server, providing centralized management and accessibility to all team members.
Step 1: Install Docker and Docker Compose
Before installing Portainer, make sure Docker is installed on your system. If it is, you can skip this step. Otherwise, run the following commands to install:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
After installation, check the versions by running the commands:
docker -v
docker compose version
This will confirm successful installation and show the versions of installed programs.
Step 2: Create a working directory
Create a directory for the application in /opt
and move to it:
cd /opt
sudo mkdir hostmanportainer
cd ./hostmanportainer
Step 3: Create a configuration file
Now create a docker-compose.yml
file in the hostmanportainer
directory. This file will describe the startup configuration. Use nano
or any other text editor to create the file:
sudo nano docker-compose.yml
Paste the following content into the file:
version: "3.3"
services:
hostmanportainer:
image: portainer/portainer-ce:latest
container_name: hostmanportainer
environment:
- TZ=Europe/London
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /opt/hostmanportainer/portainer_data:/data
ports:
- "8000:8000"
- "9443:9443"
restart: always
Description of parameters:
version: "3.3"
: Indicates the version of Docker-compose you are using. Version 3.3 is suitable for most modern applications.
services
: This section describes the services to start.
hostmanportainer
: Service name. Used as an identifier.
image: portainer/portainer-ce:latest
: Specifies the image to be used. The latest version of Community Edition is used here.
container_name: hostmanportainer
: Assigns a name to the container to make it easier to identify.
environment
: Allows you to set environment variables. For example, TZ=Europe/London
sets the time zone of the container.
volumes
:
/var/run/docker.sock: /var/run/docker.sock
allows Portainer to communicate with Docker on your host;
/opt/hostmanportainer/portainer_data:/data
creates a persistent data store.
ports
:
"8000:8000"
and "9443:9443"
open the corresponding ports to access the Portainer. 9443 is used for HTTPS connection.
restart: always
: Ensures that the container will automatically restart when necessary, for example after a server reboot.
Step 4: Launch
After creating the configuration file, run Portainer with Docker using the command:
docker compose up -d
Step 5: Access the Interface
Portainer is now running and accessible at https://<ip_or_localhost>:9443
. Open this address in your browser to access the web interface.
Step 6: Create an Administrator Account
When you first log in, you will be asked to create an administrator account. Please note that the password requires a minimum of 12 characters. After completing the registration process, you will have access to the settings and container management functionality in the interface.
To access the settings, go to the Settings section. Here we will cover the key settings that are most important for the basic configuration. We recommend reading the official documentation for a deeper understanding of all available settings.
To change your password, go to the upper right corner of the screen, click on your account name and select My account. This will allow you to update your password and other personal settings.
After studying the basic settings, let's move on to other important sections available in the left menu of the interface.
To demonstrate the process of adding a new environment, we will connect a server on Ubuntu 22.04 with Docker pre-installed. This can be either a new server or a server on which containers are already running.
docker run -d\
-p 9001:9001\
--name portainer_agent\
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker/volumes:/var/lib/docker/volumes \
portainer/agent:2.19.4
This command will launch the Portainer Agent, allowing Portainer Server to connect to the server and manage containers.
server_ip:9001
.When you go to the Home page, you will see two environments: local (the device where the application is running) and the previously added server. After selecting the previously added server, the menu on the left will update, adding management functions for the environment.
To create a new container, click on Add container. For example. let's create a container with Nginx. Specify the name, the nginx image and set up the network ports: click on publish a new network port and enter port 9090 for host, and port 80 for container.
Next, click on the Deploy the container button below and wait until the container is deployed.
Upon completion, you will be redirected to the Container list page. After deploying the container, going to http://server_ip:9090
will show running Nginx.
The App Templates section is a collection of pre-configured templates for deploying common applications and services. These templates are designed to simplify the process of creating new containers by minimizing the need for manual configuration. Users can choose from a variety of available templates that range from basic web servers to complex multi-tier applications.
When using a template, it is enough to specify some basic parameters, such as the container name, network settings and, in some cases, specific settings such as passwords or environment variables. This makes the App Templates section particularly useful for quickly testing new ideas and utilities, as well as learning and experimenting with new technologies.
Stacks are an efficient way to manage groups of containers. They are defined through docker-compose files. This simplifies the management of complex applications and provides automation and consistency in deployment.
A special feature of Stacks is choosing the configuration definition method: you can use the built-in editor to directly write or edit Docker Compose files, download a ready-made docker-compose.yml
file, or even connect a git repository to update and deploy containers automatically.
Now let's put this technology into practice. Using WordPress deployment as an example, we'll show you how to use Stacks to create and manage multi-container applications. This example will help you understand how to simplify and automate your application deployment processes using Stacks.
services:
db:
image: mariadb:10.6.4-focal
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
expose:
- 3306
- 33060
environment:
- MYSQL_ROOT_PASSWORD=hostmantest
- MYSQL_DATABASE=hostman_wp
- MYSQL_USER=hostman
- MYSQL_PASSWORD=password
wordpress:
image: wordpress:latest
ports:
- 80:80
restart: always
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=hostman
- WORDPRESS_DB_PASSWORD=password
- WORDPRESS_DB_NAME=hostman_wp
volumes:
db_data:
MYSQL_ROOT_PASSWORD=hostmantest
MYSQL_DATABASE=hostman_wp
MYSQL_USER=hostman
MYSQL_PASSWORD=password
WORDPRESS_DB_HOST=db
WORDPRESS_DB_USER=hostman
WORDPRESS_DB_PASSWORD=password
WORDPRESS_DB_NAME=hostman_wp
services:
db:
image: mariadb:10.6.4-focal
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- db_data:/var/lib/mysql
restart: always
expose:
- 3306
- 33060
wordpress:
image: wordpress:latest
ports:
- 80:80
restart: always
volumes:
db_data:
Test your WordPress functionality by going to http://server_ip:80
. You should see the WordPress start page, confirming successful deployment.
In our review, we covered all the important aspects of working with Portainer, from its installation with Docker to the details of deploying applications through Stacks. We took a detailed look at the tool's various features and settings, including user management, image repository handling, and environment coordination. The WordPress deployment example clearly showed how Portainer simplifies working with complex systems, making the management process more efficient. The article provided a comprehensive understanding of Portainer as a solution to simplify and streamline application deployment processes.