---
tags: advanced-networking
---
# Docker lab 8
read [this](https://docs.docker.com/install/linux/docker-ce/ubuntu/) before procced following commands
install docker
```bash=
# switch to root
sudo -s
# install dependencies
apt-get update
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
# add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
# add docker apt repository
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install -y docker-ce docker-ce-cli containerd.io
exit
usermod -aG docker $USER
```
:::danger
Each node should apply two network adapters. One is NAT with static IP assigned. Another is bridge for outside network access.
:::
initial a new docker swarm cluster from management node for example: `192.168.174.11`
```bash=
# the advertise ip address refferded to NAT should be fixed
docker swarm init --advertise-addr 192.168.174.11
```
after initialized cluster, you will see the join statement as shown below.
```!
docker swarm join --token SWMTKN-1-53279lczrq4nutqx53w4bbwjsxjgpmc41i7sde27wdfktltd5q-7wzhp9tcihabwbyezlzhyxe9x 192.168.174.11:2377
# run the statement on rest of nodes
```
check node status
```bash=
docker node ls
```
create nginx service and expose 8080 as public access port.
```bash=
docker service create --name webservice1 --replicas=3 --publish 8080:80 nginx
```
update public port 8080 to 80 port.
```bash=
docker service update --publish-add published=80,target=80 webservice1
```
check exposed port
```bash=
docker service inspect --format="{{json .Endpoint.Spec.Ports}}" webservice1
```