diff --git a/README.md b/README.md index 7dc53ba..20dce92 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Example Voting App ================== -This is an example Docker app with multiple services. It is run with Docker Compose and uses Docker Networking to connect containers together. +This is an example Docker app with multiple services. It is run with Docker Compose and uses Docker Networking to connect containers together. You will need Docker Compose 1.6 or later. More info at https://blog.docker.com/2015/11/docker-toolbox-compose/ @@ -17,10 +17,9 @@ Architecture Running ------- -Since this app makes use of Compose's experimental networking support, it must be started with: +Run in this directory: - $ cd vote-apps/ - $ docker-compose --x-networking up -d + $ docker-compose up -d The app will be running on port 5000 on your Docker host, and the results will be on port 5001. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b9a418c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,56 @@ +version: "2" + +services: + voting-app: + build: ./voting-app/. + volumes: + - ./voting-app:/app + ports: + - "5000:80" + links: + - redis + networks: + - front-tier + - back-tier + + result-app: + build: ./result-app/. + volumes: + - ./result-app:/app + ports: + - "5001:80" + links: + - db + networks: + - front-tier + - back-tier + + worker: + build: ./worker + links: + - db + - redis + networks: + - back-tier + + redis: + image: redis + ports: ["6379"] + networks: + - back-tier + + db: + image: postgres:9.4 + volumes: + - "db-data:/var/lib/postgresql/data" + networks: + - back-tier + +volumes: + db-data: + +networks: + front-tier: + back-tier: + + diff --git a/vote-apps/result-app/Dockerfile b/result-app/Dockerfile similarity index 100% rename from vote-apps/result-app/Dockerfile rename to result-app/Dockerfile diff --git a/vote-apps/result-app/package.json b/result-app/package.json similarity index 100% rename from vote-apps/result-app/package.json rename to result-app/package.json diff --git a/vote-apps/result-app/server.js b/result-app/server.js similarity index 95% rename from vote-apps/result-app/server.js rename to result-app/server.js index 30434e2..0675afe 100644 --- a/vote-apps/result-app/server.js +++ b/result-app/server.js @@ -24,7 +24,7 @@ io.sockets.on('connection', function (socket) { async.retry( {times: 1000, interval: 1000}, function(callback) { - pg.connect('postgres://postgres@voteapps_db_1/postgres', function(err, client, done) { + pg.connect('postgres://postgres@db/postgres', function(err, client, done) { if (err) { console.error("Failed to connect to db"); } diff --git a/vote-apps/result-app/views/app.js b/result-app/views/app.js similarity index 100% rename from vote-apps/result-app/views/app.js rename to result-app/views/app.js diff --git a/vote-apps/result-app/views/index.html b/result-app/views/index.html similarity index 100% rename from vote-apps/result-app/views/index.html rename to result-app/views/index.html diff --git a/vote-apps/result-app/views/socket.io.js b/result-app/views/socket.io.js similarity index 100% rename from vote-apps/result-app/views/socket.io.js rename to result-app/views/socket.io.js diff --git a/vote-apps/result-app/views/stylesheets/style.css b/result-app/views/stylesheets/style.css similarity index 100% rename from vote-apps/result-app/views/stylesheets/style.css rename to result-app/views/stylesheets/style.css diff --git a/vote-apps/docker-compose.yml b/vote-apps/docker-compose.yml deleted file mode 100644 index 4a14420..0000000 --- a/vote-apps/docker-compose.yml +++ /dev/null @@ -1,25 +0,0 @@ -voting-app: - build: ./voting-app/. - volumes: - - ./voting-app:/app - ports: - - "5000:80" - -redis: - image: redis - ports: ["6379"] - -worker: - build: ./worker - -db: - image: postgres:9.4 - volumes: - - "myvolume:/var/lib/postgresql/data" - -result-app: - build: ./result-app/. - volumes: - - ./result-app:/app - ports: - - "5001:80" diff --git a/vote-apps/voting-app/Dockerfile b/voting-app/Dockerfile similarity index 100% rename from vote-apps/voting-app/Dockerfile rename to voting-app/Dockerfile diff --git a/vote-apps/voting-app/app.py b/voting-app/app.py similarity index 95% rename from vote-apps/voting-app/app.py rename to voting-app/app.py index 67f576e..f811045 100644 --- a/vote-apps/voting-app/app.py +++ b/voting-app/app.py @@ -12,7 +12,7 @@ option_a = os.getenv('OPTION_A', "Cats") option_b = os.getenv('OPTION_B', "Dogs") hostname = socket.gethostname() -redis = connect_to_redis("voteapps_redis_1") +redis = connect_to_redis("redis") app = Flask(__name__) diff --git a/vote-apps/voting-app/requirements.txt b/voting-app/requirements.txt similarity index 100% rename from vote-apps/voting-app/requirements.txt rename to voting-app/requirements.txt diff --git a/vote-apps/voting-app/static/stylesheets/style.css b/voting-app/static/stylesheets/style.css similarity index 100% rename from vote-apps/voting-app/static/stylesheets/style.css rename to voting-app/static/stylesheets/style.css diff --git a/vote-apps/voting-app/templates/index.html b/voting-app/templates/index.html similarity index 100% rename from vote-apps/voting-app/templates/index.html rename to voting-app/templates/index.html diff --git a/vote-apps/voting-app/utils/__init__.py b/voting-app/utils/__init__.py similarity index 100% rename from vote-apps/voting-app/utils/__init__.py rename to voting-app/utils/__init__.py diff --git a/vote-apps/worker/Dockerfile b/worker/Dockerfile similarity index 100% rename from vote-apps/worker/Dockerfile rename to worker/Dockerfile diff --git a/vote-apps/worker/pom.xml b/worker/pom.xml similarity index 100% rename from vote-apps/worker/pom.xml rename to worker/pom.xml diff --git a/vote-apps/worker/src/main/java/worker/Worker.java b/worker/src/main/java/worker/Worker.java similarity index 95% rename from vote-apps/worker/src/main/java/worker/Worker.java rename to worker/src/main/java/worker/Worker.java index ba2362c..66c6c0c 100644 --- a/vote-apps/worker/src/main/java/worker/Worker.java +++ b/worker/src/main/java/worker/Worker.java @@ -8,8 +8,8 @@ import org.json.JSONObject; class Worker { public static void main(String[] args) { try { - Jedis redis = connectToRedis("voteapps_redis_1"); - Connection dbConn = connectToDB("voteapps_db_1"); + Jedis redis = connectToRedis("redis"); + Connection dbConn = connectToDB("db"); System.err.println("Watching vote queue");