# Commands

## References
- https://semaphoreci.com/community/tutorials/updating-services-in-a-docker-swarm-mode-cluster

## Setup server
```shell
curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc
apt-get install nfs-common
# install netshare
wget https://github.com/ContainX/docker-volume-netshare/releases/download/v0.36/docker-volume-netshare_0.36_amd64.deb
dpkg -i docker-volume-netshare_0.36_amd64.deb
service docker-volume-netshare start
```

## Manager nodes

```shell
# Manager nodes
docker swarm init --advertise-addr=10.130.8.86
# show join-token
docker swarm join-token manager
docker swarm join-token worker
docker node ls

# deloy service 
docker service create --replicas 1 --name helloworld alpine ping docker.com
docker service remove helloworld
# Update services with latest image
docker service update --image registry.gitlab.com/nginx $SERVICE_NAME
docker service update --image kong:latest $SERVICE_NAME
# Update service when config change

# Restart kong
docker service update dev_kong-gw --args "kong restart"
```

##  Worker nodes

```shell
docker swarm join --token SWMTKN-1-4brkd51qcudi543dpgb0rhc7bhfogkkacw2n5374fc0wxhuaf2-68a79g11qbrtgztkvj58fep4w 10.130.8.86:2377
docker swarm leave


```

## Working with docker stack
```shell
cd $WORKING_DIR
export STACK_NAME=dev
docker stack deploy $STACK_NAME -c stack.yml --with-registry-auth
```

## Troubleshoting
```shell
docker service ps --no-trunc $SERVICE_NAME
docker service logs $SERVICE_NAME
```