Docker lab/version note: use supported Linux-container tools and patched images. Check version compatibility before running the examples. Docker, Swarm and platform-specific deployment steps were not tested live.
What this guide covers
Portainer provides a web interface for managing containers and Swarm. Because it can control Docker, treat it as an administrator tool rather than a public application.
Before you start
Use an existing Swarm cluster and a Portainer CE release documented to support your Docker version. Use matching server and agent releases. Restrict management access with private networking or a trusted access layer.
Step 1: Choose the data node and version
Run on the manager:
sudo docker node update --availability active manager1
sudo docker node update --label-add portainer.data=true manager1
sudo docker volume create portainer_data
read -r -p 'Approved matching Portainer CE and Agent release tag: ' PORTAINER_VERSION
export PORTAINER_VERSION
This example places Portainer’s persistent data on manager1. Making that manager active allows the Portainer service to run there. It does not make the manager highly available.
Step 2: Create the management stack
Save this as portainer-stack.yml:
version: '3.8'
services:
agent:
image: portainer/agent:${PORTAINER_VERSION}
environment:
AGENT_CLUSTER_ADDR: tasks.agent
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-ce:${PORTAINER_VERSION}
command: ['-H', 'tcp://tasks.agent:9001', '--tlsskipverify']
ports:
- target: 9443
published: 9443
protocol: tcp
mode: host
volumes:
- portainer_data:/data
networks: [agent_network]
deploy:
replicas: 1
placement:
constraints:
- node.role == manager
- node.labels.portainer.data == true
networks:
agent_network:
driver: overlay
volumes:
portainer_data:
external: true
The agent mounts sensitive Docker resources. Never give this access to an untrusted application. The server’s data volume must survive replacement and be backed up.
Step 3: Deploy and finish setup
Run:
: "${PORTAINER_VERSION:?Choose an approved matching server/agent release}"
sudo --preserve-env=PORTAINER_VERSION docker stack config -c portainer-stack.yml > portainer-rendered.yml
sudo --preserve-env=PORTAINER_VERSION docker stack deploy -c portainer-stack.yml portainer
sudo docker stack services portainer
sudo docker service ps portainer_agent --no-trunc
sudo docker service ps portainer_portainer --no-trunc
sudo docker service logs --tail 80 portainer_portainer
Open the configured HTTPS management port from an allowed machine. Complete the administrator setup promptly, using the release’s documented initial-setup timeout and reset procedure if necessary.
Step 4: Verify access and backups
Confirm the intended Swarm environment appears and ordinary application tasks are visible. Configure trusted HTTPS, restrict administrators and test recovery of Portainer data. Do not expose agent ports to the internet.
Check the result
The server and agents should be healthy and the environment manageable over trusted HTTPS. Record how to administer Swarm directly if Portainer is unavailable.
Conversation
0 commentsNo comments yet. Start the conversation below.