How to Install Portainer with Docker Compose on Ubuntu 24.04


How to Install Portainer with Docker Compose on Ubuntu 24.04

Portainer is a popular tool for managing Docker containers through an easy-to-use web interface. It simplifies container management, making it accessible even to those new to Docker. In this guide, we will walk you through the steps to install Portainer using Docker Compose on Ubuntu 24.04.

Prerequisites

Before we start, ensure you have the following:

  1. An Ubuntu 24.04 server with a non-root user and sudo privileges.
  2. Docker and Docker Compose installed on your system.

Step 1: Update Your System

First, update your system to ensure all software packages are up to date. Open your terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

These commands will update the package lists and upgrade the installed packages to the latest versions.

Step 2: Create a Docker Compose File for Portainer

Now that Docker and Docker Compose are installed, we can create a Docker Compose file for Portainer.

  1. Create a directory for Portainer:
mkdir ~/portainer
cd ~/portainer

2. Create the Docker Compose file:

Create a file named docker-compose.yml:

nano docker-compose.yml

Add the following content to the file:

version: '3.8'
services:
  portainer:
    image: portainer/portainer-ce:latest
    container_name: portainer
    restart: unless-stopped
    security_opt:
      - no-new-privileges:true
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./portainer-data:/data
    ports:
- 9000:9000

  1. This configuration defines the Portainer service, maps the necessary ports, and mounts the Docker socket.
  2. Save and close the file:Press CTRL + X, then Y, and finally Enter to save the file and exit the editor.

Step 3: Deploy Portainer with Docker Compose

With your Docker Compose file ready, it’s time to deploy Portainer.

  1. Start the Portainer container:Run the following command in your terminal:
sudo docker-compose up -d

The -d flag tells Docker Compose to run the containers in the background (detached mode).

Verify that Portainer is running:

You can check if the Portainer container is running with this command:

sudo docker ps

  1. You should see the portainer/portainer-ce container listed and running.

Step 6: Access the Portainer Web Interface

Now that Portainer is running, you can access its web interface.

  1. Open your web browser:Navigate to https://your_server_ip:9000.

Conclusion

Installing Portainer using Docker Compose on Ubuntu 24.04 is straightforward and highly beneficial. This setup allows you to manage your Docker environment easily through a powerful web interface. By following this guide, you now have a secure and functional Portainer installation ready to use. Regularly update your Docker and Portainer instances to ensure a secure and smooth operation.

Enjoy managing your Docker containers with Portainer!

Fedya Serafiev

Fedya Serafiev

Fedya Serafiev owns the website linuxcodelab.eu. He finds satisfaction in helping people solve even the most complex technical problems. His current goal is to write easy-to-follow articles so that such problems do not arise at all.

Thank you for reading the article! If you found the information useful, you can donate using the buttons below: