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