Skip to content

Instantly share code, notes, and snippets.

@g0t4
Last active May 18, 2017 03:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save g0t4/1454ee7342d54aba5313ffc699d472ba to your computer and use it in GitHub Desktop.
Save g0t4/1454ee7342d54aba5313ffc699d472ba to your computer and use it in GitHub Desktop.
Docker Swarm Mode Getting Started Workshop

Shortened URL to access this gist: http://tiny.cc/swarmgs

All scripts work in bash and should work in powershell except as noted

clone this gist

git clone https://gist.github.com/g0t4/1454ee7342d54aba5313ffc699d472ba local-folder

warmup

This script pulls the images we're using in this workshop so when you need them they're already local.

git clone https://github.com/g0t4/docker-swarm-mode-getting-started/ swarmgs
cd swarmgs
git checkout necode-2017
# install dotfiles that I'm accumulating for PWD:
./warmup/pwd-dotfiles/install.sh
docker-compose -f warmup/docker-compose.yml pull --parallel

registry mirror for the day

add registry mirror to docker config (tray icon with DfW/DfM): http://172.20.1.170:5000 test connectivity: 172.20.1.170:5000/v2/_catalog

play-with-docker

http://play-with-docker.com/ - cloud hosted on-demand Linux lab environments for free!

  • You can spin up as many instances (nodes) as you want with docker installed. A session lasts 4 hours so this is great for one-off learning.
  • There's a built-in load balancer so you can access the services you startup remotely via a convention based url based on instance IP and service port. It's best to spin up a web server to see how this work, the UI will published ports and generate the link for you. Here's an example url http://pwd10_0_157_3-4000.host2.labs.play-with-docker.com/ for a service running on 10.0.157.3 port 4000.
  • Pre canned examples - training.play-with-docker.com - you can click to run pre-canned commands and inspect the environment, this is a great way to learn with pre-built content. Right now the links to connect to your app remotely don't generate properly so you'll have to guess them based on the links generated from play-with-docker.com
  • https://github.com/play-with-docker
  • Read more in the announcement post: https://blog.docker.com/2017/04/dockercon-2017-mobys-cool-hack-sessions/
  • tmux cheatsheet, a good way to split the screen with PWD:
    • execute echo set-option -g default-shell /bin/bash > ~/.tmux.conf to tell tmux to use bash shell so completions work for docker
    • shortcuts: https://gist.github.com/andreyvit/2921703 and http://view.dckr.info:8080/#16
    • important shortcuts:
    • split pane into two rows panes: Ctrl b, "
    • split pane into two columns panes: Ctrl b, %
      • switch panes with Ctrl b, arrowkey (left, right, up, down)
      • resize panes 1 row at a time with Ctrl b, Ctrl arrowkey (can keep hitting arrow key for more)
      • resize panes 5 rows at a time with Ctrl b, Meta arrowkey (meta is often esc)
      • kill pane: Ctrl b, x
      • display pane numbers: Ctrl b, q
    • create new window: Ctrl b, c
      • move windows: Ctrl b, n (n - next, p - previous)

Examples

docker run --name docs -p 4000:4000 docs/docker.github.io
docker service create --name docs -p 4000:4000 docs/docker.github.io

docker run --rm -p 8081:80 httpd
docker service create --name apache -p 8081:80 httpd

docker run --rm -p 8081:80 nginx
docker service create --name nginx -p 8081:80 nginx

Visualizing the cluster

manomarks/visualizer

docker service create \
  --name=viz \
  --publish=8090:8080 \
  --constraint=node.role==manager \
  --mount=type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
  manomarks/visualizer

Balance -> Customer stack

Create the stack "manually"

docker network create -d overlay --subnet 10.0.9.0/24 backend
docker service create --name balance -p 5000:3000 --network backend swarmgs/balance
docker service create --name customer --network backend swarmgs/customer
# open website http://IP:5000/balance/1 - it is broken!
docker service logs balance # shows CUSTOMER_API value
docker service update --env-add MYWEB_CUSTOMER_API=customer:3000 balance

Course files

https://github.com/g0t4/docker-swarm-mode-getting-started

version: '3'
# Version 2 docker-compose: https://gist.github.com/g0t4/52ff6c0a740c2048cd9c4e68a117ec0f#file-docker-compose-yml
# git clone https://gist.github.com/g0t4/52ff6c0a740c2048cd9c4e68a117ec0f tc-standalone
services:
teamcity:
image: jetbrains/teamcity-server:2017.1.1
volumes:
- teamcity-server-datadir:/data/teamcity_server/datadir
- teamcity-server-logs:/opt/teamcity/logs
ports:
- 8111:8111
teamcity-agent:
image: jetbrains/teamcity-agent:2017.1.1
environment:
SERVER_URL: http://teamcity:8111
deploy:
replicas: 3
volumes:
teamcity-server-datadir:
teamcity-server-logs:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment