Convert app to use Compose file 2

Signed-off-by: Ben Firshman <ben@firshman.co.uk>
This commit is contained in:
Ben Firshman 2016-01-25 18:20:23 +00:00
parent 4f9d03c3cc
commit 94c0d7b507
5 changed files with 38 additions and 27 deletions

View File

@ -1,7 +1,7 @@
Example Voting App 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/ 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: Since this app makes use of Compose's experimental networking support, it must be started with:
$ cd vote-apps/ $ 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. The app will be running on port 5000 on your Docker host, and the results will be on port 5001.

View File

@ -1,9 +1,13 @@
version: "2"
services:
voting-app: voting-app:
build: ./voting-app/. build: ./voting-app/.
volumes: volumes:
- ./voting-app:/app - ./voting-app:/app
ports: ports:
- "5000:80" - "5000:80"
links:
- redis
redis: redis:
image: redis image: redis
@ -11,6 +15,9 @@ redis:
worker: worker:
build: ./worker build: ./worker
links:
- db
- redis
db: db:
image: postgres:9.4 image: postgres:9.4
@ -23,3 +30,7 @@ result-app:
- ./result-app:/app - ./result-app:/app
ports: ports:
- "5001:80" - "5001:80"
links:
- db
volumes:
myvolume:

View File

@ -24,7 +24,7 @@ io.sockets.on('connection', function (socket) {
async.retry( async.retry(
{times: 1000, interval: 1000}, {times: 1000, interval: 1000},
function(callback) { 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) { if (err) {
console.error("Failed to connect to db"); console.error("Failed to connect to db");
} }

View File

@ -12,7 +12,7 @@ option_a = os.getenv('OPTION_A', "Cats")
option_b = os.getenv('OPTION_B', "Dogs") option_b = os.getenv('OPTION_B', "Dogs")
hostname = socket.gethostname() hostname = socket.gethostname()
redis = connect_to_redis("voteapps_redis_1") redis = connect_to_redis("redis")
app = Flask(__name__) app = Flask(__name__)

View File

@ -8,8 +8,8 @@ import org.json.JSONObject;
class Worker { class Worker {
public static void main(String[] args) { public static void main(String[] args) {
try { try {
Jedis redis = connectToRedis("voteapps_redis_1"); Jedis redis = connectToRedis("redis");
Connection dbConn = connectToDB("voteapps_db_1"); Connection dbConn = connectToDB("db");
System.err.println("Watching vote queue"); System.err.println("Watching vote queue");