Create volume

docker volume create portainer_data

Create portainer-agent-stack.yml

version: '3.2'

services:
  agent:
    image: portainer/agent:2.18.3
    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:2.18.3
    command: -H tcp://tasks.agent:9001 --tlsskipverify
    ports:
      - "9443:9443"
      - "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
    attachable: true

volumes:
  portainer_data:

start swarm

curl -L <https://downloads.portainer.io/ce2-18/portainer-agent-stack.yml> -o portainer-agent-stack.yml
docker stack deploy -c portainer-agent-stack.yml portainer

Example swarm

docker node ls
# stop
docker node update --availability drain ...
# start
docker node update --availability active ...

Docker stand alone

docker stop portainer
docker rm portainer
docker rmi portainer/portainer-ce:latest
docker run -d -p 9444:8000 -p 9443:9443 --name portainer \\
    --restart=always \\
    -v /var/run/docker.sock:/var/run/docker.sock \\
    -v portainer_data:/data \\
    portainer/portainer-ce:latest