Docker-machine swarm; how to open ports on VM -
trying out new "swarm mode", following this. have created 3 vm's via docker-machine create --driver virtual box <name>
. how open ports on them?
it might work docker run -p <public-port>:<internal-port> <image>
executed on node. however, since want run swarm, guess better follow guide solve routing mess here. if follow author's suggestions, need create swarm (i.e. docker host cluster) first docker-machine
commands, e.g.
docker-machine create --driver virtualbox swarm-1 docker-machine create --driver virtualbox swarm-2
setup swarm with
eval $(docker-machine env swarm-1) docker swarm init --advertise-addr $(docker-machine ip swarm-1)
join other machines (if there any) with
eval $(docker-machine env swarm-2) docker swarm join \ --token <yourtoken> 192.168.99.106:2377
where found in output of docker swarm init
command.
then author suggests create network
docker network create --driver overlay webnet
and publish port defining service like
docker service create --name webapp --replicas=2 --network webnet --publish 80:8000 <yourdockerimage>
in example, yourdockerimage running service internally on port 8000, mapped docker host port 80. then, can access service e.g. by
curl http://<ip-address of docker swarm node>:80
note, can access ip address of docker swarm node. docker swarm magic , route request container of service, if have chosen ip address of node no container of service running on.
Comments
Post a Comment