Reputation: 607
I've successfully managed to deploy a docker-compose.yml using docker-machine. The problem I have is with scaling. Trying to scale a node.js app that uses port 3000. How can I scale a docker-compose service. I know I can use docker-compose scale web=3
in a swarm of 1 node (server) but this doesn't work because I specified port 3000, which results in a conflict.
How can I get it to work in a dynamic manner without resorting to using HAProxy or Nginx?
Dockerfile
FROM node:wheezy
# replace this with your application's default port
EXPOSE 3000
ADD . /install
WORKDIR /install
ENV NODE_PATH /usr/local/lib/node_modules/
RUN npm install -g $(cat packages) && rm -rf npm_cache /tmp/* && npm install
# Install node modules and start
CMD ["npm", "install"]
CMD ["node", "."]
docker-compose.yml
version: "2"
services:
web:
build: .
ports:
- "3000:3000"
links:
- mongo
environment:
- "affinity:image==node:wheezy"
mongo:
image: mongo
volumes:
- ./appdb:/data/db
volumes:
mongo-data:
driver: local
Upvotes: 2
Views: 617
Reputation: 1853
As you are actually BINDING to the host, it wouldn't be possible without a proxy or load balancer.
See this issue on the topic via GitHub where a user was asking a similar question:
https://github.com/docker/compose/issues/3088
Here is an example of how you can do it with a load balancer, making it easy:
https://github.com/vegasbrianc/docker-compose-demo/blob/master/docker-compose.yml
Upvotes: 2