For the Example Voting App for docker, I am trying to start multiple replicas of the vote
app and dynamically allocate host port to container port 80.
Then, I tried to setup a nginx as a reverse proxy that would forward all requests for vote app to the associated container.
For some reason, when I hit the URL for the ex2 instance, I continue to get the nginx default page and not the voting page.
docker-compose.yml
services:
vote:
image: ritikbilala/dockervotingapp_vote:latest
deploy:
replicas: 2
# use python rather than gunicorn for local dev
command: python app.py
depends_on:
redis:
condition: service_healthy
volumes:
- ./vote:/app
networks:
- front-tier
- back-tier
rproxy:
build: ./rproxy
deploy:
replicas: 1
depends_on:
- vote
ports:
- "80:80"
networks:
- front-tier
result:
image: ritikbilala/dockervotingapp_result:latest
deploy:
replicas: 1
# use nodemon rather than node for local dev
command: nodemon server.js
depends_on:
db:
condition: service_healthy
volumes:
- ./result:/app
ports:
- "8080:80"
- "5858:5858"
networks:
- front-tier
- back-tier
worker:
image: ritikbilala/dockervotingapp_worker:latest
deploy:
replicas: 1
depends_on:
redis:
condition: service_healthy
db:
condition: service_healthy
networks:
- back-tier
redis:
image: redis:5.0-alpine3.10
deploy:
replicas: 1
volumes:
- "./healthchecks:/healthchecks"
healthcheck:
test: /healthchecks/redis.sh
interval: "5s"
ports: ["6379"]
networks:
- back-tier
db:
image: postgres:9.4
deploy:
replicas: 1
environment:
POSTGRES_USER: "postgres"
POSTGRES_PASSWORD: "postgres"
volumes:
- "db-data:/var/lib/postgresql/data"
- "./healthchecks:/healthchecks"
healthcheck:
test: /healthchecks/postgres.sh
interval: "5s"
networks:
- back-tier
volumes:
db-data:
networks:
front-tier:
back-tier:
Dockerfile for nginx
# Using latest ubuntu base image
FROM ubuntu:latest
LABEL author="Debal Das"
# add curl for healthcheck
RUN apt-get update \
&& apt-get install -y nginx
# Copy reverse proxy configuration file
COPY default.conf /etc/nginx/conf.d/default.conf
COPY ./includes/ /etc/nginx/includes/
#RUN nginx -t
# Make port 80 available for links and/or publish
EXPOSE 80
# Define our command to be run when launching the container
CMD ["nginx", "-g", "daemon off;"]
default.conf
server {
listen 80;
listen [::]:80;
server_name _;
location / {
proxy_pass http://vote:80;
}
}
Output from running curl vote:80 inside the nginx container
root@258365be8730:/# curl vote:80
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cats vs Dogs!</title>
<base href="/index.html">
<meta name = "viewport" content = "width=device-width, initial-scale = 1.0">
<meta name="keywords" content="docker-compose, docker, stack">
<meta name="author" content="Tutum dev team">
<link rel='stylesheet' href="/static/stylesheets/style.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
</head>
<body>
<div id="content-container">
<div id="content-container-center">
<h3>Cats vs Dogs!</h3>
<form id="choice" name='form' method="POST" action="/">
<button id="a" type="submit" name="vote" class="a" value="a">Cats</button>
<button id="b" type="submit" name="vote" class="b" value="b">Dogs</button>
</form>
<div id="tip">
(Tip: you can change your vote)
</div>
<div id="hostname">
Processed by container ID aff76a269759
</div>
</div>
</div>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
</body>