Setting up Portainer using Docker Compose

In this section, we'll set up Portainer using Docker Compose. Portainer is a web-based interface for creating, managing, and monitoring containers, making it accessible to users without extensive command-line experience.

Create a New Directory

mkdir portainer

Navigate to the New Directory

cd portainer

Create a Docker Compose File

nano docker-compose.yaml

Paste the following YAML Configuration

version: "2.2"
services:
  portainer:
    image: portainer/portainer-ce:latest
    container_name: portainer
    volumes:
      - /portainer:/data
      - /var/run/docker.sock:/var/run/docker.sock
      - /etc/localtime:/etc/localtime:ro
    ports:
      - 8000:8000
      - 9000:9000
    restart: unless-stopped

Save and Exit the Text Editor

Press `Ctrl` + `X`, then `Y`, and `Enter`

Install Docker Compose (if not installed)

sudo apt install docker-compose

Bring up the Portainer Container

docker-compose up -d