Skip to content

Instantly share code, notes, and snippets.

@codeasashu
Created January 20, 2019 20:41
Show Gist options
  • Save codeasashu/594ad85eac93979797e1b130ef94152e to your computer and use it in GitHub Desktop.
Save codeasashu/594ad85eac93979797e1b130ef94152e to your computer and use it in GitHub Desktop.
Steps to launch a consul server deamon
1. run
`docker run -it -h node \
-p 8500:8500 \
-p 53:53/udp \
progrium/consul \
-server \
-bootstrap \
-advertise $DOCKER_IP`
2. run registrator
`docker run -it -d \
-v /var/run/docker.sock:/tmp/docker.sock \
-h $DOCKER_IP gliderlabs/registrator \
consul://$DOCKER_IP:8500`
====If you want LB====
3. Go in app directory and do this:
`docker build -t python/server .`
4. Run 2 "app" instances
`docker run -it -d \
-e "SERVICE_NAME=app" \
-p 8000:8000 python/server
`
`docker run -it -d \
-e "SERVICE_NAME=app" \
-p 8001:8000 python/server
`
5. Run nginx lb image
`docker run -p 80:80 -d --name nginx --net host --volume $PWD/templates:/templates
-e CONSUL_URL:$DOCKER_IP stakater/nginx-with-consul-template:latest`
6. Now try reaching `$DOCKER_IP` using
`curl http://$DOCKER_IP` and see the response
=====if using as service discovery=======
Sidenote: You can shut down nginx image in step 5 and python apps in step 4 here (optional)
7. Create a simple webapp (see https://github.com/codeasashu/consul-webapp-demo)
8. start webapp using `docker-compose up -d` and see the magic
FROM python:3
EXPOSE 8000
CMD ["python", "-m", "http.server"]
upstream app {
least_conn;
{{range service "app"}}
server {{.Address}}:{{.Port}};
{{else}}server 127.0.0.1:65535;{{end}}
}
server {
listen 80 default_server;
location / {
proxy_pass http://app;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment