Last active
December 17, 2015 01:04
-
-
Save rafabene/79b0bc0a8b4e8ee2a9d5 to your computer and use it in GitHub Desktop.
Docker host solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
master: | |
image: centos | |
hostname: master | |
net: my-swarm-network | |
command: /bin/sh -c "while true; do echo executing master; sleep 1; done" | |
slave: | |
image: centos | |
net: my-swarm-network | |
command: /bin/sh -c "while true; do echo executing slave; sleep 1; done" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ./swarm-create.sh | |
$ eval "$(docker-machine env --swarm swarm-master)" | |
$ docker network create --driver overlay my-swarm-network | |
$ docker-compose up -d | |
$ docker exec -ti swarm-node-02/rafaelbenevides_master_1 ping master | |
PING master (10.0.0.3) 56(84) bytes of data. | |
64 bytes from master (10.0.0.3): icmp_seq=1 ttl=64 time=0.032 ms | |
64 bytes from master (10.0.0.3): icmp_seq=2 ttl=64 time=0.048 ms | |
$ docker exec -ti swarm-node-02/rafaelbenevides_master_1 ping rafaelbenevides_slave_1 | |
PING rafaelbenevides_slave_1 (10.0.0.2) 56(84) bytes of data. | |
64 bytes from rafaelbenevides_slave_1 (10.0.0.2): icmp_seq=1 ttl=64 time=1.41 ms | |
$ docker exec -ti swarm-node-01/rafaelbenevides_slave_1 sh -c 'HOST=$(hostname); ping $HOST' | |
PING 6ff0763e7495 (10.0.0.2) 56(84) bytes of data. | |
64 bytes from 6ff0763e7495 (10.0.0.2): icmp_seq=1 ttl=64 time=0.031 ms | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cho "Creating Multi Host Keystore" | |
docker-machine create -d virtualbox mh-keystore | |
eval "$(docker-machine env mh-keystore)" | |
echo "Starting Consul at Keystore Machine" | |
docker run -d -p "8500:8500" -h "consul" progrium/consul -server -bootstrap | |
echo "Creating Swarm master ..." | |
docker-machine create -d virtualbox --swarm --swarm-master --swarm-strategy "spread" --swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" --engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-master | |
echo "Creating Swarm node 01 ..." | |
docker-machine create -d virtualbox --swarm --swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" --engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-node-01 | |
echo "Creating Swarm node 02 ..." | |
docker-machine create -d virtualbox --swarm --swarm-discovery="consul://$(docker-machine ip mh-keystore):8500" --engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500" --engine-opt="cluster-advertise=eth1:2376" swarm-node-02 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To check what was the generated hostname for the slave instance, run the following:
You will see something like this:
Now that you found that the generated hostname for slave is rafaelbenevides_slave_1, try to ping that hostname address from the slave instance itself:
The command above fails because /etc/hosts of the slave instance does not have the generated hostname entry the same way as in master's.
That is the issue.