Following the Get Started: Stack server stuck loading page endlessly - docker

I've been following the docker get started guide quite closely - except for a few changes in my python app, which I have confirmed are working without issue from the version I have pushed to docker hub.
However, when I get to Part 3 and attempt to load up localhost:80, the page simply loads endlessly.
My commands:
$ docker swarm init
Swarm initiated: ...
$ docker stack deploy -c docker-compose.yml
Creating network getstartedlab_webnet
Creating service getstartedlab_web
$ docker stack ps getstartedlab
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
fhxqr2u8hxar getstartedlab_web.1 mctague/friendlyhello:2 cube Running Running 29 seconds ago
4t9mu9r8147e getstartedlab_web.2 mctague/friendlyhello:2 cube Running Running 28 seconds ago
duute2pvgu9z getstartedlab_web.3 mctague/friendlyhello:2 cube Running Running 30 seconds ago
9kav6v27qfjn getstartedlab_web.4 mctague/friendlyhello:2 cube Running Running 29 seconds ago
1s2imbiuk6e2 getstartedlab_web.5 mctague/friendlyhello:2 cube Running Running 29 seconds ago
$ docker logs <one of the running containers>
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
$ curl localhost:80
< either an endless loading that I have to cancel with ^C,
*OR* Connection refused >
docker-compose.yml
version: "3"
services:
web:
image: mctague/friendlyhello:2
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:

In some systems, curl connects to ip6 by default for localhost. So you can run curl using:
$ curl 127.0.0.1:80
or
$ curl -4 localhost:80

Alexey's answer was my issue too. I resolved the issue disabling ipv6 (and therefore defaulting to ipv4) by adding the following 2 lines (this is on CentOS 7) to /etc/sysctl.conf:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
then executing sysctl -p (all as root/su).

Related

How to configure port mapping for replicated containers in Docker Compose?

The goal is to run two containers of publisher-app. One container should be mapped to port 8080 on the host machine, and the other on 8081. Here is the docker-compose:
publisher_app:
ports:
- "8080-8081:8080"
environment:
server.port: 8080
deploy:
mode: replicated
replicas: 2
Two containers are created, but as I understand, both ports are assigned to the first one, and the second one produces this error: Ports are not available: listen tcp 0.0.0.0:8081: bind: address already in use.
Here is the output of docker ps -a:
6c7067b4ebee spring-boot-rest-kafka_publisher_app "java -jar /app.jar" 33 seconds ago Up 28 seconds 0.0.0.0:8080->8080/tcp, 0.0.0.0:8081->8080/tcp spring-boot-rest-kafka_publisher_app_2
70828ba8f370 spring-boot-rest-kafka_publisher_app "java -jar /app.jar" 33 seconds ago Created spring-boot-rest-kafka_publisher_app_1
Docker engine version: 20.10.11
Docker compose version: 2.2.1
How to handle this case? Your help will be very appreciated.
Here is the source code: https://github.com/aleksei17/springboot-rest-kafka-mysql/blob/master/docker-compose.yml
tried locally on Windows 10 and failed similarly, both with v2 and with v2 disabled.
It seems like a compose issue
when tried on arch: amd64 fedora based linux distro with package manager installed docker and manually installing docker-compose 1.29.2 (using the official guide for linux) worked:
compose file:
version : "3"
services:
web:
image: "nginx:latest"
ports:
- "8000-8020:80"
docker command:
docker-compose up --scale web=5
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b304d397b2cd nginx:latest "/docker-entrypoint.…" 14 seconds ago Up 7 seconds 0.0.0.0:8004->80/tcp, :::8004->80/tcp testdir_web_4
a8c6f177a6e6 nginx:latest "/docker-entrypoint.…" 14 seconds ago Up 7 seconds 0.0.0.0:8003->80/tcp, :::8003->80/tcp testdir_web_3
b1abe53e7d7d nginx:latest "/docker-entrypoint.…" 14 seconds ago Up 8 seconds 0.0.0.0:8002->80/tcp, :::8002->80/tcp testdir_web_2
ead91e9df671 nginx:latest "/docker-entrypoint.…" 14 seconds ago Up 9 seconds 0.0.0.0:8001->80/tcp, :::8001->80/tcp testdir_web_5
65ffd6a87715 nginx:latest "/docker-entrypoint.…" 24 seconds ago Up 21 seconds 0.0.0.0:8000->80/tcp, :::8000->80/tcp testdir_web_1

Cannot use docker-compose with overlay network

I'm pretty baffled what's going on here, but I've narrowed it down to a very small test case. Here's my docker-compose file:
version: "3.7"
networks:
cl_net_overlay:
driver: overlay
services:
redis:
image: "redis:alpine"
networks:
- cl_net_overlay
The cl_net_overlay network doesn't exist. When I run this with:
docker-compose up
It stalls for a little while, then says:
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
To deploy your application across the swarm, use `docker stack deploy`.
Creating network "tmp_cl_net_overlay" with driver "overlay"
Recreating tmp_redis_1 ... error
ERROR: for tmp_redis_1 Cannot start service redis: attaching to network failed, make sure your network options are correct and check manager logs: context deadline exceeded
ERROR: for redis Cannot start service redis: attaching to network failed, make sure your network options are correct and check manager logs: context deadline exceeded
ERROR: Encountered errors while bringing up the project.
This file was working fine for me on my previous laptop. My docker and docker-compose should be up to date since this is a brand new laptop. Is there some piece of the puzzle I'm missing?
05:01:11::mlissner#gabbro::/tmp
↪ docker --version
Docker version 19.03.1, build 74b1e89
05:01:57::mlissner#gabbro::/tmp
↪ docker-compose --version
docker-compose version 1.24.1, build 4667896b
Any ideas what's going on here? I've been trying to get it to work all day and I'm feeling a little like I'm losing my mind.
Small follow up. The message says:
make sure your network options are correct and check manager logs
I have no idea how to check the manager logs. That might be a useful first step?
Another follow up, per comments. If I try to deploy this I get no logs and it's unable to start up:
05:44:32::mlissner#gabbro::~/Programming/courtlistener/docker/courtlistener
↪ docker stack deploy --compose-file /tmp/docker-compose.yml test2
Creating network test2_cl_net_overlay2
Creating service test2_redis
05:44:50::mlissner#gabbro::~/Programming/courtlistener/docker/courtlistener
↪ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
5y7o01o5mifn test2_redis replicated 0/1 redis:alpine
05:44:57::mlissner#gabbro::~/Programming/courtlistener/docker/courtlistener
↪ docker service ps 5y
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
0kbph0ie8qth test2_redis.1 redis:alpine gabbro Ready Rejected 4 seconds ago "mkdir /var/lib/docker: read-o…"
inr81c3r4un7 \_ test2_redis.1 redis:alpine gabbro Shutdown Rejected 9 seconds ago "mkdir /var/lib/docker: read-o…"
tl1h6dp90ur2 \_ test2_redis.1 redis:alpine gabbro Shutdown Rejected 14 seconds ago "mkdir /var/lib/docker: read-o…"
jacv2yvkspix \_ test2_redis.1 redis:alpine gabbro Shutdown Rejected 19 seconds ago "mkdir /var/lib/docker: read-o…"
7cm6e8snf517 \_ test2_redis.1 redis:alpine gabbro Shutdown Rejected 19 seconds ago "mkdir /var/lib/docker: read-o…"
Another idea: Running as root. Same issue.
Do you have the right plugins (see more bellow on the docker info command)?
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
It works on:
$ docker swarm init
$ docker-compose up
WARNING: The Docker Engine you're using is running in swarm mode.
Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.
To deploy your application across the swarm, use `docker stack deploy`.
Creating network "stackoverflow-57701373_cl_net_overlay" with driver "overlay"
Pulling redis (redis:alpine)...
alpine: Pulling from library/redis
9d48c3bd43c5: Pull complete
(...)
redis_1 | 1:M 29 Aug 2019 01:27:31.969 * Ready to accept connection
When:
$ docker --version
Docker version 19.03.1-ce, build 74b1e89e8a
and info:
$ docker info
Client:
Debug Mode: false
Server:
(...)
Server Version: 19.03.1-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: active
NodeID: ff5mogx0ph4pgmwm2zrbhmjb4
Is Manager: true
ClusterID: vloixv7g75jflw5i1k81neul1
Managers: 1
Nodes: 1
(...)

Trouble connecting to my docker app via VM IP

Solved at bottom
But why do I have to append :4000?
I'm following the docker get-started Guide here, https://docs.docker.com/get-started/part4/
I'm fairly certain I've done everything correctly, but am wondering why I can't connect to view the app after deploying it.
I've set my env to my VM, myvm1, for reference to following commands.
docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
099e16249604 beresj/getting-started:part2 "python app.py" 12 seconds ago Up 12 seconds 80/tcp getstartedlab_web.5.y0e2k1r1ev47u24e5iufkyn3i
6f9a24b343a7 beresj/getting-started:part2 "python app.py" 12 seconds ago Up 12 seconds 80/tcp getstartedlab_web.3.1pls3osj3uhsb5dyqtt4ts8j6
docker image ls -a
REPOSITORY TAG IMAGE ID CREATED SIZE
beresj/getting-started <none> e290b6208c21 22 hours ago 131MB
docker stack ls
NAME SERVICES ORCHESTRATOR
getstartedlab 1 Swarm
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
myvm1 * virtualbox Running tcp://192.168.99.100:2376 v18.09.6
myvm2 - virtualbox Running tcp://192.168.99.101:2376 v18.09.6
docker stack ps getstartedlab
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
vkxx79fh3h85 getstartedlab_web.1 beresj/getting-started:part2 myvm2 Running Running 3 minutes ago
qexbaa3wz0pd getstartedlab_web.2 beresj/getting-started:part2 myvm2 Running Running 3 minutes ago
1pls3osj3uhs getstartedlab_web.3 beresj/getting-started:part2 myvm1 Running Running 3 minutes ago
ucuwen1jrncf getstartedlab_web.4 beresj/getting-started:part2 myvm2 Running Running 3 minutes ago
y0e2k1r1ev47 getstartedlab_web.5 beresj/getting-started:part2 myvm1 Running Running 3 minutes ago
curl 192.168.99.100
curl: (7) Failed to connect to 192.168.99.100 port 80: Connection refused
docker info
Containers: 2
Running: 2
Paused: 0
Stopped: 0
Images: 1
Server Version: 18.09.6
...
Swarm: active
NodeID: 0p9qrax9h3by0fupat8ufkfbq
Is Manager: true
ClusterID: 7vnqdk85n8jx6fqck9k7dv2ka
Managers: 1
Nodes: 2
Default Address Pool: 10.0.0.0/8
...
Node Address: 192.168.99.100
Manager Addresses:
192.168.99.100:2377
...
Kernel Version: 4.14.116-boot2docker
Operating System: Boot2Docker 18.09.6 (TCL 8.2.1)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 989.4MiB
Name: myvm1
I would expect to see what I was able to see when I just ran it on my local machine instead of on a VM in a swarm (I think I have the lingo correct?)
Not sure how to check open ports.
Again: this works if I simply remove the stack, unset the docker-machine environment, and just run:
docker stack deploy -c docker-compose.yml getstartedlab
not on the vm.
Thank you in advance. (Also, I'm new hence the get-started guide so I appreciate any help)
Edit
It works if I append :4000 to the VM IP in my url, ex: 192.168.99.100:4000 or 192.168.99.101:4000. It shows the two container Id's listed in 'docker container ls' for myvm1, and the other three are from myvm2. Could anyone tell me why I have to append 4000? Is it because I have ports: "4000:80" in my docker-compose.yml?
Not sure if this will help but if you use docker inspect <instance_id_here>, you can see what ports are exposed.
Exposed ports aren't open ports. You would need to bind a host port to a container port in the docker-compose.yml in order for it to be to be open.

Connection refused when running my vertx3 http handler in docker swarm

I'm trying to deploy a vertx3 service on docker swarm but when I run
$ curl localhost:4000
curl: (7) Failed to connect to localhost port 4000: Connection refused
and I can't figure out how to make it work, help appreciated. See below the code and more info.
This is my vertx3 application
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
public class MainVerticle extends AbstractVerticle {
#Override
public void start(Future<Void> fut) {
vertx.createHttpServer().requestHandler(r -> {
r.response().end("<h1>Powered by Vert.x3</h1>");
}).listen(8080, result -> {
if (result.succeeded()) {
fut.complete();
} else {
fut.fail(result.cause());
}
});
}
}
this is my dockerfile
FROM vertx/vertx3
ENV VERTICLE_NAME com.shop.services.products.MainVerticle
ENV VERTICLE_FILE target/products-3.5.1.jar
ENV VERTICLE_HOME /usr/verticles
EXPOSE 8080
COPY $VERTICLE_FILE $VERTICLE_HOME/
WORKDIR $VERTICLE_HOME
ENTRYPOINT ["sh", "-c"]
CMD ["exec vertx run $VERTICLE_NAME -cp $VERTICLE_HOME/*"]
and this is my docker-compose.yml
version: "3"
services:
web:
image: sergionava89/products:v1
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "4000:8080"
networks:
- webnet
networks:
webnet:
I try to run a local docker swarm
docker swarm init
then I get this message
Error response from daemon: could not choose an IP address to advertise since this system has multiple addresses on interface enp0s25 (2a02:c7d:501a:f200:84fc:532e:737a:7a21 and 2a02:c7d:501a:f200:ad08:5748:44d4:6726) - specify one with --advertise-addr
so I run the following
docker swarm init --advertise-addr 2a02:c7d:501a:f200:84fc:532e:737a:7a21
then launch the container
docker stack deploy -c docker-compose.yml shop
to which I get
Creating network shop_webnet
Creating service shop_web
when I try to hit the endpoint I get
$ curl localhost:4000
curl: (7) Failed to connect to localhost port 4000: Connection refused
Output of docker service
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
sj8k1hd26cbk shop_web replicated 5/5 sergionava89/products:v1 *:4000->8080/tcp
docker service ps shop_web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
sjsoh7atv24x shop_web.1 sergionava89/products:v1 sergio-ThinkPad-T431s Running Running 9 minutes ago
owakk9xqty69 shop_web.2 sergionava89/products:v1 sergio-ThinkPad-T431s Running Running 9 minutes ago
yvlopiq6vtjh shop_web.3 sergionava89/products:v1 sergio-ThinkPad-T431s Running Running 9 minutes ago
op7yv8vuliuk shop_web.4 sergionava89/products:v1 sergio-ThinkPad-T431s Running Running 9 minutes ago
z8imj3b572tg shop_web.5 sergionava89/products:v1 sergio-ThinkPad-T431s Running Running 9 minutes ago
As suggested in the comments 127.0.0.1:4000 works

Docker SWARM Not working

I"m following the tutorial from https://docs.docker.com/get-started/part3/ on a Mac. This tutorial is to setup a Docker service using swarm node. However, I'm getting Empty reply from server if I goto http://localhost. I have verified that port 80 is with a Docker process, and the Docker container are running as well.
Mac-Machine: docker stack deploy -c docker-compose.yml getstartedlab
Creating network getstartedlab_webnet
Creating service getstartedlab_web
Mac-Machine:docker user1$ lsof -i tcp:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 7592 user1 44u IPv4 0xfc021b13bc914389 0t0 TCP *:http (LISTEN)
Mac-Machine:docker user1$ curl http://localhost
curl: (52) Empty reply from server
Mac-Machine:docker user1$ docker service ls
ID NAME MODE REPLICAS IMAGE
w4dghr7jcpca getstartedlab_web replicated 5/5 dockhub-user1/get-started:part1
Mac-Machine:docker user1$ docker service ps w4dghr7jcpca
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
4oykrq8ge8yl getstartedlab_web.1 dockhub-user1/get-started:part1 moby Running Running about a minute ago
ba1n3m1pis2f getstartedlab_web.2 dockhub-user1/get-started:part1 moby Running Running about a minute ago
kmy8n4tm0n44 getstartedlab_web.3 dockhub-user1/get-started:part1 moby Running Running about a minute ago
cyeyozw6u8x7 getstartedlab_web.4 dockhub-user1/get-started:part1 moby Running Running about a minute ago
0evm9skw7p44 getstartedlab_web.5 dockhub-user1/get-started:part1 moby Running Running about a minute ago
Mac-Machine:docker user1$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5223c52b2014 dockhub-user1/get-started#sha256:2d3934a04a4aecc453652678489b2d96ce8d3dc5457aa8afdaeb71dbeff236ff "python app.py" 2 minutes ago Up About a minute 80/tcp getstartedlab_web.1.4oykrq8ge8ylw3ilbufxdp4t0
910b7b7521b3 dockhub-user1/get-started#sha256:2d3934a04a4aecc453652678489b2d96ce8d3dc5457aa8afdaeb71dbeff236ff "python app.py" 2 minutes ago Up About a minute 80/tcp getstartedlab_web.4.cyeyozw6u8x7j1zy1k82dugrn
d3ebd24cfe9a dockhub-user1/get-started#sha256:2d3934a04a4aecc453652678489b2d96ce8d3dc5457aa8afdaeb71dbeff236ff "python app.py" 2 minutes ago Up 2 minutes 80/tcp getstartedlab_web.5.0evm9skw7p44npujg6nbhckmy
ba29ffbdf2ce dockhub-user1/get-started#sha256:2d3934a04a4aecc453652678489b2d96ce8d3dc5457aa8afdaeb71dbeff236ff "python app.py" 2 minutes ago Up About a minute 80/tcp getstartedlab_web.2.ba1n3m1pis2flttytx87nucvb
6d8af1744b75 dockhub-user1/get-started#sha256:2d3934a04a4aecc453652678489b2d96ce8d3dc5457aa8afdaeb71dbeff236ff "python app.py" 2 minutes ago Up About a minute 80/tcp getstartedlab_web.3.kmy8n4tm0n44jgb1tc34qgeww
Here is the docker-compose.yml
version: "3"
services:
web:
# replace username/repo:tag with your name and image details
image: dockhub-user1/get-started:part1
deploy:
replicas: 5
resources:
limits:
cpus: "0.1"
memory: 50M
restart_policy:
condition: on-failure
ports:
- "80:80"
networks:
- webnet
networks:
webnet:
Image dockhub-user1/get-started:part1 was created using the following Docker file.
# 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
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install -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"]
Here is the app.py file
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)
After spending a whole afternoon debugging the issue, I found out that it was caused by Kubernetes. Stopping it from Docker Desktop resolved the issue.

Resources