This image allows to auto register all the swarm nodes in a Portainer running in the same cluster and network.
You need to create a global service and pass some options and env vars.
- Network: It's important to attach this service in a network where Portainer is attached.
- Mounts
- Hostname file: This allows to detect the name of the host where the service task is running.
- Docker socket: This allows to expose the socket to Portainer.
HOST_HOSTNAME: (Optional) Just in case you want to change the mount point of the file that contains the name of the hostPORTAINER_ADDR: Name and port where Portainer is configuredPORTAINER_USER: Username used to login to PortainerPORTAINER_PASS: Password used to login to PortainerSLEEP_IF_WORKER: Seconds to wait before register the node if it's a worker
The SLEEP_IF_WORKER is useful to avoid that a worker is the first to register to Portainer, because it loads by default
the first registered endpoint, if it's a worker you won't have the cluster overview in a first sight.
This allows to register just the current node. You need to be sure that the portainer network is attachable.
docker container run \
--name portainer-endpoint \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--mount type=bind,source=/etc/hostname,target=/etc/host_hostname \
--network portainer \
-e HOST_HOSTNAME=/etc/host_hostname \
-e PORTAINER_ADDR=portainer:9000 \
-e PORTAINER_USER=admin \
-e PORTAINER_PASS=12341234 \
softonic/portainer-endpointThis allows to register each node in Portainer.
docker service create --with-registry-auth \
--name portainer-endpoint \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--mount type=bind,source=/etc/hostname,target=/etc/host_hostname \
--network portainer \
--mode global \
-e HOST_HOSTNAME=/etc/host_hostname \
-e PORTAINER_ADDR=portainer:9000 \
-e PORTAINER_USER=admin \
-e PORTAINER_PASS=12341234 \
softonic/portainer-endpointYou can use a Swarm Stack to deploy Portainer and the automatic registration feature. Just execute the stack file in a swarm cluster:
git clone [email protected]:softonic/portainer-endpoint.git
cd portainer-endpoint
export VOLUME_DRIVER=local
export PORTAINER_PASS=12341234
export PORTAINER_ENC_PASS=$(docker run --rm httpd:2.4-alpine htpasswd -nbB admin ${PORTAINER_PASS} | cut -d ":" -f 2)
echo $PORTAINER_PASS | docker secret create portainer_password.v1 --label portainer -
docker stack deploy --compose-file docker-compose.yml portainerOnce the stack is deployed and running you can go to the port 9000 on any of your cluster nodes to reach Portainer.
You'll see all the nodes in your cluster are already registered.
- It needs Docker >17.04 because of the version of the stack file.
- In this example I'm using a secret for the Portainer password in the endpoints.
- Its usage is optional, you can use the environment variable with the password in clear text (not recommended).