I don't understand what I missed.
docker.compose.yml
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: svezday/friendlyhello:part-1
deploy:
replicas: 5
restart_policy:
condition: on-failure
resources:
limits:
cpus: "0.1"
memory: 50M
ports:
- "80:80"
networks:
- webnet
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
networks:
- webnet
networks:
webnet:
Dockerfile
# Use an official Python runtime as a parent image
FROM python:2.7-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
app.py
from flask import Flask
from redis import Redis, RedisError
import os
import socket
# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)
app = Flask(__name__)
@app.route("/")
def hello():
try:
visits = redis.incr("counter")
except RedisError:
visits = "<i>cannot connect to Redis, counter disabled</i>"
html = "<h3>Hello {name}!</h3>" "<b>Hostname:</b> {hostname}<br/>" "<b>Visits:</b> {visits}"
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
I'm on ubuntu 18, with vitualbox.
This is the vm
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 * virtualbox Running tcp://192.168.99.100:2376 v18.09.0
requirements.txt
Flask
Redis
myvm2 - virtualbox Running tcp://192.168.99.101:2376 Unknown Unable to query docker version: Get https://192.168.99.101:2376/v1.15/version: x509: certificate is valid for 192.168.99.103, not 192.168.99.101
docker-machine ssh myvm1
docker swarm init --advertise-addr 192.168.99.101:2377 getStartNow
docker-machine ssh myvm2
docker swarm join --token SWMTKN-1-29dkoqd6tskoqszzrdpcnw0nbmrgbrw9xr27yoxtvapodk6qmg-3tv01eh1ts0n97s5c5zq7q4ju 192.168.99.100:2377
docker-machine ssh myvm1
docker stack deploy -c docker.compose.yml getStartNow
docker stack ls
NAME SERVICES ORCHESTRATOR
getStartNow 2 Swarm
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
w9l0khipey4v getStartNow_visualizer replicated 1/1 dockersamples/visualizer:stable *:8080->8080/tcp
3yoifm7inujf getStartNow_web replicated 5/5 svezday/friendlyhello:part-1 *:80->80/tcp
AND HERE IS MY PROBLEM
curl http://192.168.99.100:80
curl: (7) Failed to connect to 192.168.99.100 port 80: Connection refused
curl http://192.168.99.100:8080
curl: (7) Failed to connect to 192.168.99.100 port 8080: Connection refused
I had the same problem. I followed Elavaud solution here and it worked for me.
So:
I downloaded boot2docker.iso from here
Check active virtual-machine
docker-machine ls
destroy all virtual machines (myvm1 and myvm2)
docker-machine rm $(docker-machine ls -q)
Create again the virtual-machines specifying the path of your downloaded boot2docker.iso
docker-machine create --driver virtualbox --virtualbox-boot2docker-url path_to_your_boot2docker.iso virtual_machine_name
In my case the path was ~/Downloads/boot2docker.iso so i did
docker-machine create --driver virtualbox --virtualbox-boot2docker-url ~/Downloads/boot2docker.iso myvm1
docker-machine create --driver virtualbox --virtualbox-boot2docker-url ~/Downloads/boot2docker.iso myvm2
Last think, I saw your docker-compose.yml is differente from docker-compose.yml created in get_started part3. I don't know if that could be the problem. In my case I used the same docker-compose.yml in get_started part3, so when I access to my app i use the port 4000
curl http://192.168.99.101:4000/
I also had this problem, but found a slightly simpler solution; rather than downloading boot2docker and pointing to it on your machine, you can just set the virtualbox-boot2docker-url
flag to a url for the downgraded version; e.g.:
docker-machine create myvm1 --virtualbox-boot2docker-url "https://github.com/boot2docker/boot2docker/releases/download/v18.06.1-ce/boot2docker.iso"
docker-machine create myvm2 --virtualbox-boot2docker-url "https://github.com/boot2docker/boot2docker/releases/download/v18.06.1-ce/boot2docker.iso"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With