{"id":483,"date":"2024-02-18T17:36:38","date_gmt":"2024-02-18T15:36:38","guid":{"rendered":"https:\/\/it4home.dk\/?p=483"},"modified":"2024-02-18T17:37:37","modified_gmt":"2024-02-18T15:37:37","slug":"installing-portainer-in-docker-swarm-a-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/it4home.dk\/index.php\/2024\/02\/18\/installing-portainer-in-docker-swarm-a-step-by-step-guide\/","title":{"rendered":"Installing Portainer in Docker Swarm: A Step-by-Step Guide"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-post pdfprnt-top-right\"><a href=\"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/483?print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\" ><\/a><a href=\"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/483?print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\" ><img decoding=\"async\" src=\"https:\/\/it4home.dk\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">Portainer is an essential tool for managing your Docker environments, offering a simple yet powerful UI for handling containers, images, networks, and more. Integrating Portainer into your Docker Swarm enhances your cluster&#8217;s management, making it more efficient and user-friendly. Here&#8217;s a concise guide on installing Portainer within a Docker Swarm setup, leveraging the power of NFS for persistent data storage.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Prerequisites<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Docker Swarm cluster is already initialized.<\/li>\n\n\n\n<li>NFS server is set up for persistent storage (in this case, at 192.168.0.220).<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Prepare the NFS Storage<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding with Portainer installation, ensure you have a dedicated NFS share for Portainer data:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Create a directory on your NFS server (<code>192.168.0.220<\/code>) that will be used by Portainer: <code>\/data\/portainer\/data<\/code>.<\/li>\n\n\n\n<li>Ensure this directory is exported and accessible by your Swarm nodes.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Create the Portainer Service<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The following Docker Compose file is designed for deployment in a Docker Swarm environment and utilizes NFS for storing Portainer&#8217;s data persistently.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>version: '3.2'\n\nservices:\n  agent:\n    image: portainer\/agent:latest\n    volumes:\n      - \/var\/run\/docker.sock:\/var\/run\/docker.sock\n      - \/var\/lib\/docker\/volumes:\/var\/lib\/docker\/volumes\n    networks:\n      - agent_network\n    deploy:\n      mode: global\n      placement:\n        constraints: &#91;node.platform.os == linux]\n\n  portainer:\n    image: portainer\/portainer-ee:latest\n    command: -H tcp:\/\/tasks.agent:9001 --tlsskipverify\n    ports:\n      - \"9000:9000\"\n      - \"8000:8000\"\n    volumes:\n      - type: volume\n        source: portainer_data\n        target: \/data\n        volume:\n          nocopy: true\n    networks:\n      - agent_network\n    deploy:\n      mode: replicated\n      replicas: 1\n      placement:\n        constraints: &#91;node.role == manager]\n\nnetworks:\n  agent_network:\n    driver: overlay\n    attachable: true\n\nvolumes:\n  portainer_data:\n    driver: local\n    driver_opts:\n      type: nfs\n      o: addr=192.168.0.220,nolock,soft,rw\n      device: \":\/data\/portainer\/data\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Deploy Portainer<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To deploy Portainer, save the above configuration to a file named <code>portainer-agent-stack.yml<\/code>. Then, execute the following command on one of your Swarm manager nodes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker stack deploy -c portainer-agent-stack.yml portainer<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This command deploys the Portainer server and its agent across the Swarm. The agent provides cluster-wide visibility to the Portainer server, enabling management of the entire Swarm from a single Portainer instance.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: Access Portainer<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Once deployed, Portainer is accessible via <code>http:\/\/&lt;your-manager-node-ip&gt;:9000<\/code>. The initial login requires setting up an admin user and password. After logging in, you can connect Portainer to your Docker Swarm environment by selecting it from the home screen.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Conclusion<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Integrating Portainer into your Docker Swarm setup provides a robust, web-based UI for managing your cluster&#8217;s resources. By leveraging NFS for persistent storage, you ensure that your Portainer configuration and data remain intact across reboots and redeployments, enhancing the resilience and flexibility of your Docker Swarm environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Portainer is an essential tool for managing your Docker environments, offering a simple yet powerful UI for handling containers, images, networks, and more. Integrating Portainer into your Docker Swarm enhances your cluster&#8217;s management, making&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":485,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/comments?post=483"}],"version-history":[{"count":1,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/483\/revisions"}],"predecessor-version":[{"id":484,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/posts\/483\/revisions\/484"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/media\/485"}],"wp:attachment":[{"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/media?parent=483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/categories?post=483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/it4home.dk\/index.php\/wp-json\/wp\/v2\/tags?post=483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}