소스 검색

Convert app to use Compose file 2

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
Ben Firshman 9 년 전
부모
커밋
94c0d7b507
5개의 변경된 파일38개의 추가작업 그리고 27개의 파일을 삭제
  1. 2 2
      README.md
  2. 32 21
      vote-apps/docker-compose.yml
  3. 1 1
      vote-apps/result-app/server.js
  4. 1 1
      vote-apps/voting-app/app.py
  5. 2 2
      vote-apps/worker/src/main/java/worker/Worker.java

+ 2 - 2
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/
 
@@ -20,7 +20,7 @@ Running
 Since this app makes use of Compose's experimental networking support, it must be started with:
 
     $ 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.
 

+ 32 - 21
vote-apps/docker-compose.yml

@@ -1,25 +1,36 @@
-voting-app:
-  build: ./voting-app/.
-  volumes:
-    - ./voting-app:/app
-  ports:
-    - "5000:80"
+version: "2"
+services:
+  voting-app:
+    build: ./voting-app/.
+    volumes:
+      - ./voting-app:/app
+    ports:
+      - "5000:80"
+    links:
+      - redis
 
-redis:
-  image: redis
-  ports: ["6379"]
+  redis:
+    image: redis
+    ports: ["6379"]
 
-worker:
-  build: ./worker
+  worker:
+    build: ./worker
+    links:
+      - db
+      - redis
 
-db:
-  image: postgres:9.4
-  volumes:
-    - "myvolume:/var/lib/postgresql/data"
+  db:
+    image: postgres:9.4
+    volumes:
+      - "myvolume:/var/lib/postgresql/data"
 
-result-app:
-  build: ./result-app/.
-  volumes:
-    - ./result-app:/app
-  ports:
-    - "5001:80"
+  result-app:
+    build: ./result-app/.
+    volumes:
+      - ./result-app:/app
+    ports:
+      - "5001:80"
+    links:
+      - db
+volumes:
+  myvolume:

+ 1 - 1
vote-apps/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");
       }

+ 1 - 1
vote-apps/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__)
 
 

+ 2 - 2
vote-apps/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");