4

I followed their documentation here to install Portainer as shown below:

version: '2'

services:
  portainer:
    image: portainer/portainer
    command: -H unix:///var/run/docker.sock
    restart: always
    ports:
      - 9000:9000
      - 8000:8000
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data

volumes:
  portainer_data:

However, I later found out that their file browser functionality is only supported by the Portainer agent.

I also found the following example:

version: '3.2'

services:
  agent:
    image: portainer/agent
    environment:
      # REQUIRED: Should be equal to the service name prefixed by "tasks." when
      # deployed inside an overlay network
      AGENT_CLUSTER_ADDR: tasks.agent
      # AGENT_PORT: 9001
      # LOG_LEVEL: debug
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    networks:
      - agent_network
    deploy:
      mode: global
      placement:
        constraints: [node.platform.os == linux]

  portainer:
    image: portainer/portainer
    command: -H tcp://tasks.agent:9001 --tlsskipverify
    ports:
      - "9000:9000"
      - "8000:8000"
    volumes:
      - portainer_data:/data
    networks:
      - agent_network
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [node.role == manager]

networks:
  agent_network:
    driver: overlay

volumes:
  portainer_data:

but my project is small, and I don't want to use Docker stack or a cluster.

So, how can I install it purely using only docker-compose?

Andreas Violaris
  • 2,465
  • 5
  • 13
  • 26
SkyRar
  • 1,107
  • 1
  • 20
  • 37

3 Answers3

6

I did it in the most simple way:

version: '3.2'

services:
  agent:
    image: portainer/agent
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes

  portainer:
    image: portainer/portainer-ce
    command: -H tcp://agent:9001 --tlsskipverify
    ports:
      - "9000:9000"
    volumes:
      - portainer_data:/data


volumes:
  portainer_data:

Please send pull requests if you have ideas to make this better: https://github.com/barfooos/simple-portainer-deployment

barfooos
  • 61
  • 1
  • 3
2

If you don't have a cluster, you can deploy Portainer with a single agent by utilizing the following YAML file:

version: '3.9'

services:

  # Agent service configuration
  agent:
    # Use the portainer/agent Docker image
    image: portainer/agent
    volumes:
      # Mount the host's Docker socket into the container
      - /var/run/docker.sock:/var/run/docker.sock
      # Mount the host's Docker volumes into the container
      - /var/lib/docker/volumes:/var/lib/docker/volumes

  # Portainer service configuration
  portainer:
    # Use the portainer/portainer-ce Docker image
    image: portainer/portainer-ce
    # Specify the command for the container
    command: -H tcp://agent:9001 --tlsskipverify
    # Publish the container's port 9000 to the host's port 9000
    ports:
      - "9000:9000"
    volumes:
      # Mount the host's Docker socket into the container
      - /var/run/docker.sock:/var/run/docker.sock
      # Create a named volume for persistent Portainer data storage
      - portainer_data:/data
    # Wait for the agent service to be ready
    depends_on:
      - agent

volumes:
  # Volume for Portainer data persistence
  portainer_data:

Although it is well-documented, you may refer here for more information.

Andreas Violaris
  • 2,465
  • 5
  • 13
  • 26
-1

Works for me From

version: '3.2'

services:
  agent:
    container_name: agent
    image: portainer/agent:2.6.3
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /var/lib/docker/volumes:/var/lib/docker/volumes
    ports:
      - "9001:9001"
Valera
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 20 '22 at 12:32