logo
Programming

Docker stack setup

O

Ohidur Rahman Bappy

MAR 27, 2025

Install docker engine on the target host

docker swarm init

For getting the token:

docker swarm join-token worker

Using docker context

docker context create <name> --docker "host=ssh://user@domain"
  
docker context use <name>
  

Deploy

docker stack deploy -c <compose-file_path> <stack-name>

to ignore warning:

docker stack deploy -c <compose-file_path> <stack-name> --with-registry-auth

Secrets

docker secret create <name>

e.g

docker secret create db-password

printf 'youor password' | docker secret create db-password -

Scaling / Load balancing

docker service scale <stack-name>=<number>
docker service logs <stack-name> -f

Rollback

docker service rollback <stack-name>

Prepare the host

adduser deploy
usermod -aG docker deploy

# switch to the new user
su - deploy

# create .ssh dir
mkdir .ssh

# paste the public keys into authrized_keys

echo "your---public-keys" > .ssh/authorized_keys

# harden the security ssh by opening authorized_keys and addming command before the key

command="docker system dial-stdio" ssh-ed5519 .........


Generate ssh key

ssh-keygen -t ed25519 -C "deploy@domain"

# copy the public key to clipboard
wl-copy < <public-key-file-name>.pub