Hello, everyone! Today we’re going to dive into the details of how to install and use Portainer with Docker Compose, a powerful tool that allows you to visually and very easily manage your Docker containers. If you’re tired of memorizing complex CLI commands or typing them every time, this article will take your container management life to the next level! โจ
—]
๐ 1. What is a Portainer?
Portainer is an open source visualization management tool for container orchestration platforms like Docker, Docker Swarm, and Kubernetes. In short, think of it as a user interface (UI) tool that allows you to create, deploy, manage, and monitor containers through clean, web-based dashboards rather than commands.
Key features of Portainer:.
- Intuitive dashboard: Get an at-a-glance view of the status of your currently running containers, images, volumes, networks, and more.
- Easy container management: Start, stop, restart, and delete containers with just a few clicks, view logs, access shells, and more.
- Application templates: Easily deploy popular applications like WordPress, Nginx, and more using predefined templates.
- Volume and network management: Visually create and manage Docker volumes and networks.
- User and access control: Create multiple users and grant each user access to specific resources to facilitate team-level management.
- Multi-environment management: Unified management of multiple Docker hosts or Swarm clusters into a single Portainer.
—.
๐ 2. Why use Docker Compose?
There are many ways to install Portainer, but using Docker Compose is the simplest, most reproducible, and most manageable.
What is Docker Compose?
Docker Compose is a tool for defining and running multiple Docker containers together. Using a YAML file called docker-compose.yml
, you can define your application’s services, network, volumes, and more at once, and build and run the entire application stack with a single command.
Benefits of utilizing Docker Compose for your Portainer installation:.
- Simplicity: Instead of typing multiple complex
docker run
commands, you can define all settings in a singledocker-compose.yml
file. - Reproducibility: With just a YAML file, you can quickly deploy Portainer with the same settings in any environment. This is also advantageous for backup and restore.
- Easy to manage: Starting, stopping, and updating Portainer services can be easily controlled with the
docker-compose
command. - Versioning: You can save the
docker-compose.yml
file to a version control system like Git to manage change history.
—.
๐ ๏ธ 3. Create a Docker Compose file for your Portainer installation
Now let’s install Portainer using Docker Compose. Before we begin, make sure you have Docker and Docker Compose installed on your system.
Preparation:
- Verify Docker installation:** Run
docker --version
in a terminal to verify that Docker is installed. - verify Docker Compose installation:** Run the
docker compose version
ordocker-compose --version
command to verify that Docker Compose is installed. (Newer Docker versions have a built-indocker compose
command.)
Step-by-step installation: ร
1. Create a directory for Portainer installation. First, create a directory to store Portainer-related files and navigate to that directory.
mkdir portainer
cd portainer
**2. Create a docker-compose.yml
file***.
Inside the portainer
directory, create a file named docker-compose.yml
and paste the following contents into it
touch docker-compose.yml
3. Write the contents of the docker-compose.yml
file.
Now open the docker-compose.yml
file with a text editor (vi, nano, VS Code, etc.) and write the following content
version: '3.8' # Docker Compose file version (latest recommended)
services:
portainer:
image: portainer/portainer-ce:latest # Use the Portainer Community Edition (CE) image
container_name: portainer # Specify the container name (optional)
restart: always # Always restart on container shutdown (e.g., auto-start on server reboot)
ports:
- "9000:9000" # Port to connect to Portainer web UI (host:container)
- "8000:8000" # Port for Portainer Edge Agent communication (enable if needed)
volumes:
- /var/run/docker.sock:/var/run/docker.sock # Docker daemon socket mount (required)
- portainer_data:/data # Mount volume for Portainer data persistence
volumes:
/data: # Define named volumes to store Portainer data. portainer_data: # Define named volumes to store Portainer data.
Description of each configuration item: ฮ
version: '3.8'
: Specifies the version of the Docker Compose file. We recommend using the 3.x version to utilize the latest features.services:
: Defines the services (containers) to run under this section.portainer:
: Defines a service namedportainer
. You can change this to any name you want.image: portainer/portainer-ce:latest
: This means that you want to use the latest image of Portainer Community Edition. The:latest
tag will always fetch the latest version. If you want to use a specific version, you can specify it likeportainer/portainer-ce:2.19.4
.container_name: portainer
: Specifies the name of the container to be created asportainer
. This name allows for easy control, such asdocker stop portainer
.restart: always
: Sets this container to always restart when the container is shut down for any reason or when the Docker daemon is restarted.ports:
: Defines the port mapping between the host and the container.- "9000:9000"
: Forwards requests coming in on port 9000 on the host to port 9000 on the container. This is used to access the Portainer web UI.- "8000:8000"
: This port is required when using the Portainer Edge Agent to manage remote environments. We recommend leaving it open for the future, even if you don’t need it today.
volumes:
: Defines the volume mapping between containers and hosts. Very important for data persistence.- /var/run/docker.sock:/var/run/docker.sock
: One of the most important parts Mounts the host’s Docker daemon socket inside the Portainer container, allowing Portainer to control the host’s Docker environment. Without this volume, Portainer cannot manage any containers.- portainer_data:/data
: Mounts a named volume namedportainer_data
in the/data
directory inside the container. Portainer’s settings, user information, application data, etc. are stored in this volume so that the data is preserved even if the container is deleted.
volumes:
(top level) : Define a named volume to use, such asportainer_data
. Docker will automatically create and manage this volume for you.
—.
โถ๏ธ 4. Run and access Portainer with Docker Compose
Once you’re done writing the docker-compose.yml
file, it’s time to run Portainer and access the web UI.
**1. Run Portainer
In the directory where the docker-compose.yml
file is located (the portainer
directory), run the following command.
docker compose up -d
up
: Starts the service defined in thedocker-compose.yml
file.-d
: (detached mode) Run the container in the background, making the terminal available again.
When you run the command, you will see the process of downloading a Docker image, creating a Portainer container, and running it.
**2. Check the execution Verify that the Portainer container is running normally.
Run “`bash docker ps
The output should show the `portainer` container using the `portainer/portainer-ce` image in the `Up` state.
container id image command created status ports names xxxxxxxxxxxx portainer/portainer-ce:latest “/portainer” 5 seconds ago Up 4 seconds 0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp portainer
**3. Access the Portainer web UI
Open a web browser and connect to the following address.
If you installed Docker on a remote server, enter the IP address of the server instead of `localhost` (for example, `http://192.168.1.100:9000`).
**4. Initialize Portainer
* **Create an admin account:** When you first connect, you will be prompted to create an admin account (Admin user). Set a strong password and click the "Create user" button. ๐]
* **Select environment:** On the next screen, you will need to select the Docker environment you want Portainer to manage. Typically, if you have installed on a single server, select the "Local" environment.
* **Local:** Manage the Docker environment on the current server where Portainer is installed.
* **Agent:** Manages Portainer Agent installed on another remote Docker environment.
* **Kubernetes:** Manage a Kubernetes cluster.
* **Azure ACI:** Manages Azure Container Instances.
Select "Local" and click the "Connect" button.
You are now connected to the Portainer dashboard and ready to start visually managing your Docker environment! ๐
---.
### โจ 5. Tips for using Portainer and a tour of key features
When you access the Portainer dashboard, you'll find several menus to help you manage your Docker environment.
* **Dashboard:** It summarizes the overall status of your current environment, including containers, images, and volumes.
* **Containers:** View a list of all running and stopped containers. You can click on a container to view its logs, change its state (start/stop/restart), change environment variables, access its shell, etc. ๐ฆ
* **Images:** View a list of downloaded Docker images, build or delete images, and more.
* **Volumes:** Manage created Docker volumes. Essential for maintaining persistence of container data. ๐พ
* **Networks:** Create and manage Docker networks. Controls inter-container communication and external access settings. ๐
* **Stacks:** Manage deployed applications using Docker Compose files (stacks). You can deploy a stack by uploading a YAML file or by writing it directly with the web editor. ๐.
* **App Templates:** Use predefined templates to easily deploy popular applications like WordPress, Redis, and more with just a few clicks. ๐
* **Users:** Add multiple users and manage their permissions for team projects. ๐ฅ
---.
### ๐ค 6. Troubleshooting and additional considerations
**Frequently Encountered Issues:** **See
* **Port conflict (`Address already in use`):** Occurs when the port 9000 or 8000 set in the `docker-compose.yml` file is already in use by another application. Please change the host port in the `ports` section, for example, `9001:9000` instead of `9000:9000` (e.g., `- "9001:9000"`)
* **`/var/run/docker.sock` permissions issue:** Occurs when the Portainer container cannot access the Docker socket. Running as the `root` user or a user account belonging to the `docker` group usually works fine. If you continue to experience permissions issues, check the owner or group permissions of `docker.sock`.
* **Cannot access Portainer:** Port 9000 may be blocked by your firewall. Check your server's firewall settings and make sure to allow port 9000.
**Additional considerations:**
* **Security:**
* Portainer is a powerful administration tool, so we do not recommend exposing the default port 9000 of the web UI directly to the outside world. We recommend using a reverse proxy like Nginx or Caddy to set up HTTPS, and configuring your firewall to only allow access from specific IPs.
* Set strong administrator passwords and change them regularly.
* **Updates:**
To update Portainer to the latest version, run the following command in the directory where the `docker-compose.yml` file is located.
```bash
docker compose pull portainer # Download the latest Portainer image
docker compose up -d --force-recreate # Delete the existing container and recreate it with a new image
- Back up your data: The
portainer_data
volume stores all of Portainer’s settings and data. It is recommended that you back up this volume periodically to be prepared for any eventuality. You can check the actual storage path with the commanddocker volume inspect portainer_data
.
—.
Closing thoughts
In this article, you learned how to easily and reliably install Portainer using Docker Compose. Portainer is a very useful tool for those who are new to managing Docker containers, as well as for experienced users who want to manage them efficiently.
With Portainer’s intuitive web UI, you should now be able to work with containers without the need for complicated CLI commands. We hope you enjoy your container management journey! ๐ If you have any questions, feel free to ask them in the comments.