Assumption
I have torchserve installed and running inside a WSL2 Docker container that makes an API for the Pytorch model.
What I would like to achieve.
I would like to receive a list of models when I run the curl command.
curl http://127.0.0.1:8081/models
Expected Results
{
"models": [
{
"modelName": "densenet161",
"modelUrl": "densenet161.mar"
}
]
}
Occurring problems
The following message is returned.
<HTML>
<HEAD><TITLE>Redirection</TITLE></HEAD>
<BODY><H1>Redirect</H1></BODY>
What I tried
The following commands were executed from the Torchserve container
curl 127.0.0.1:8081/models
I tried with the IP address of the Docker container (172.17.0.5) but it returned an error.
curl 172.17.0.5:8081/models
curl: (52) Empty reply from server
When running the Docker container, I did the following port forwarding.
I ran the curl command from host to host IP address with the same result.
docker run -it --gpus all -v /home:/home -p 8080:8080 -p 8081:8081 -p 8082:8082 --shm-size 8GB ts_test
curl http://172.19.108.214:8081/models
With the -L option, an error was returned with the following results.
root#f0b48fd29ec1:~# curl -L http://127.0.0.1:8081/models
curl: (52) Empty reply from server
With the -v option, the following results were returned.
root#f0b48fd29ec1:~# curl -v http://127.0.0.1:8081/models
* Trying 10.77.8.70...
* TCP_NODELAY set
* Connected to proxy.mei.co.jp (10.77.8.70) port 8080 (#0)
> GET http://127.0.0.1:8081/models HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/7.58.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 301 Moved Permanently
< Server: BlueCoat-Security-Appliance
< Location:http://10.75.28.231
< Connection: Close
<
<HTML>
<HEAD><TITLE>Redirection</TITLE></HEAD>
<BODY><H1>Redirect</H1></BODY>
* Closing connection 0
What are some possible reasons why the curl command is not returning results?
The following commands produced the expected results.
It seems that the proxy was affecting the results.
root#f0b48fd29ec1:~/torchserve-sample# curl http://127.0.0.1:8081/models --noproxy "*"
{
"models": [
{
"modelName": "densenet161",
"modelUrl": "densenet161.mar"
}
]
}
Related
OS: Ubuntu 20.04 LTS
Docker version 20.10.7, build 20.10.7-0ubuntu1~20.04.2
Tried this (minimal way to reproduce), the previous day it works normally:
docker run --name nginx1 -p 8089:80 -d nginx:alpine
Works normally:
docker ps
CONTAINER ID IMAGE COMMAND CREATED
74faabf44b8e nginx:alpine "/docker-entrypoint.…" 5 minutes ago
STATUS PORTS NAMES
Up 5 minutes 0.0.0.0:8089->80/tcp, :::8089->80/tcp nginx1
curl inside docker works:
docker exec -it 74faabf44b8e sh
/ # curl localhost
<!DOCTYPE html>
<html>
<head>
....
But when accessed from the host:
netstat -antpel | grep 8089
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:8089 0.0.0.0:* LISTEN 0 82748695 -
tcp6 0 0 :::8089 :::* LISTEN 0 82751546 -
curl -v localhost:8089
* Trying 127.0.0.1:8089...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8089 (#0)
> GET / HTTP/1.1
> Host: localhost:8089
> User-Agent: curl/7.68.0
> Accept: */*
>
--> stuck without a response, after a while:
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
What's the possible cause of this?
This also doesn't work for another container (PostgreSQL), seems the docker-proxy does not forward back the response from docker?
already tried:
reinstall docker.io
delete all containers and re-create
docker network prune
Ubuntu version: 22.04 LTS
Docker version: 20.10.17, build 100c701
Installation procedure: https://docs.docker.com/engine/install/ubuntu/
I am encountering the same problem as you on more recent versions of Ubuntu & Docker: Everything seems to be working fine except that the host is not able to reach the container on port, as defined by the -p <docker-host-port>:<docker-container-port> option.
curl http://localhost:<port> works from within the container, but not from outside despite port binding ...
I tried to restart docker daemon, restart machine, remove container, recreate container, remove image, recreate image, uninstall completely docker, reinstall docker from scratch. I just don't understand why Docker is acting funky like this on this specific instance (Ubuntu 22.04 + Docker).
Following up on
How to configure docker container proxy?
I'm having problem passing my localhost proxy into docker container:
$ curl --proxy socks5://localhost:18888 https://goolge.ca
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
docker run -ti -p 18888:18888 ...
# within docker
$ curl --proxy socks5://localhost:18888 https://goolge.ca
curl: (7) Failed to connect to localhost port 18888: Connection refused
$ curl --proxy https://localhost:18888 https://goolge.ca
curl: (7) Failed to connect to localhost port 18888: Connection refused
$ curl --proxy http://localhost:18888 https://goolge.ca
curl: (7) Failed to connect to localhost port 18888: Connection refused
$ curl --proxy socks5://0.0.0.0:18888 https://goolge.ca
curl: (7) Failed to connect to 0.0.0.0 port 18888: Connection refused
This is under macOS.
I also tried to pass --net=host from docker cli, but the result is the same.
What I've missed?
If you are running the commands in docker container's bash then you should use
#within docker
$ curl --proxy socks5://0.0.0.0:18888 https://goolge.ca
I started following this docker/KONG installation tutorial where they create a network called "kong-net" and fire up the KONG and postgresql containers.
Then I jumped to this docker/kong tutorial the registers a sample flask container as an API in KONG..
I did not see any thing alarming while configuring the KONG container with the flask service and associated routes.
The sample flask container seems to work fine:
curl http://localhost:5055/api/v1/test1
curl http://localhost:5055/api/v1/test2
I get the expected result:
{"message":"first end point test1 is called","status_code":200}
The results of these commands look good:
curl -i -X POST --url http://localhost:8001/services/ --data 'name=testApi' --data 'url=http://localhost:5055'
curl http://localhost:8001/routes | json_pp
Everything is great until I get this command to test KONG:
curl -i -X GET --url http://localhost:8000/api/v1/test1 --header 'Host: localhost'
I think KONG is supposed to forward this to the sample flask container.
Instead I see this error:
HTTP/1.1 502 Bad Gateway
Date: Wed, 08 May 2019 18:20:00 GMT
Content-Type: text/plain; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: kong/1.1.2
X-Kong-Upstream-Latency: 1
X-Kong-Proxy-Latency: 35
Via: kong/1.1.2
An invalid response was received from the upstream server
In the logs for the KONG container I see this:
2019/05/08 16:56:57 [error] 38#0: *167134 connect() failed (111:
Connection refused) while connecting to upstream, client:
172.19.0.1, server: kong, request: "GET /api/v1/test1 HTTP/1.1",
upstream: "http://127.0.0.1:5055/api/v1/test1", host: "localhost"
172.19.0.1 - - [08/May/2019:16:56:57 +0000] "GET /api/v1/test1
HTTP/1.1" 502 69 "-" "curl/7.59.0"
It looks like KONG cannot see localhost:5055.
I'm worried about that network the first tutorial had me create.
I tried stopping, rebuilding and re-running the flask container with this command (so the flask was part of the network too):
docker run -d --name flask --network=kong-net -p 5055:5055 flask:test
Alas, this did not help. Same error!
When I type
docker network inspect kong-net
I now see that the flask container is part of kong-net. Is this necessary?
I tried this command and it worked:
docker exec -ti kong sh -c "curl http://172.19.0.4:5055/api/v1/test1 "
{"message":"first end point test1 is called","status_code":200}
I'm doing all this with Windows10/cygwin-bash/docker18.09.2 with docker/kubernetes turned on.
Questions:
Does the sample flask app need to part of the kong-net?
The tutorial seems be saying that kong should be able to see 127.0.0.1:5055. Is this correct? Is the tutorial wrong?
How can I make this command work?
curl -i -X GET --url http://localhost:8000/api/v1/test1 --header 'Host: localhost'
When Kong is installed as a docker container 'localhost' means loopback address of the Kong container - NOT the host. Endpoints registered in Kong should be resolvable from the Kong container.
So, you can change your registration to use actual IP and Port of the backend service as reachable by Kong container, so, if your backend is also a docker container and its port 5055 is mapped to port 15055 on the host, then registration in Kong should use host IP and port 15055.
You need to register the routes:
curl -i -X POST \
--url http://localhost:8001/services/testApi/routes \
--data 'hosts[]=localhost' \
--data 'paths[]=/api/v1/test1' \
--data 'strip_path=false' \
--data 'methods[]=GET'
I'm moving away from docker-compose files to using docker swarm but I just can't figure this out.
I have two services - a nginx proxy, and a website both running just fine in docker swarm (which has three nodes)
The issue I've got is I need to configure nginx to proxy_pass to the backend website. Currently the only way I can get this to work is by specifying an ip address of one of the nodes.
My services are created as follows:
docker service create --mount type=bind,source=/../nginx.conf,target=/etc/nginx/conf.d/default.conf \
-p 443:443 \
--name nginx \
nginx
and
docker service create --name ynab \
-p 5000:5000 \
--replicas 2 \
scottrobertson/fintech-to-ynab
I've tried using the service name but that just doesn't work.
Really I don't think I should have to even expose the ynab service ports (at least that would work when I used docker-compose)
In one of the nginx containers I have tried the following:
root#5fabc5611264:/# curl http://ynab:5000/ping
curl: (6) Could not resolve host: ynab
root#5fabc5611264:/# curl http://nginx:5000/ping
curl: (6) Could not resolve host: nginx
root#5fabc5611264:/# curl http://127.0.0.1:5000/ping
curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
root#5fabc5611264:/# curl http://localhost:5000/ping
curl: (7) Failed to connect to localhost port 5000: Connection refused
Using the process list I tried connecting to the running instances id, and name:
root#5fabc5611264:/# curl http://ynab.1:5000/ping
curl: (6) Could not resolve host: ynab.1
root#5fabc5611264:/# curl http://pj0ekc6i7n0v:5000/ping
curl: (6) Could not resolve host: pj0ekc6i7n0v
But I can only get it to work if I use the nodes public ip addresses:
root#5fabc5611264:/# curl http://192.168.1.52:5000/ping
pong
root#5fabc5611264:/# curl http://192.168.1.53:5000/ping
pong
root#5fabc5611264:/# curl http://192.168.1.51:5000/ping
pong
I really don't want to use a public ip in case that node goes down. I'm sure I must just be doing something wrong!
The services need to be connected to the same network for this to work.
$ docker network create -d overlay fake-internet-points
$ docker service create --name service_one --network fake-internet-points [...]
$ docker service create --name service_two --network fake-internet-points [...]
I'm stuck with getting port mapping to work with a docker instance I've built. curl localhost in the docker container shows the application is working fine, but curl from host returns:
* Rebuilt URL to: 127.0.0.1/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
I've exposed the port with -p flag. I've tried mapping all sorts of different ports and what not but no dice.
Any ideas on how I could debug this? And/or common problems with port mapping?
If you're doing curl outside of the container - it won't work. If I understand you correctly then you have several variants:
Use command docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID - more on Docker Inspect.
Use command docker port $CONTAINER_NAME - more on Docker Port.
UPD #1
Execute command docker inspect -f '{{ .NetworkSettings.IPAddress }}' <CONTAINER_NAME>. It should show you internal IP-address and then try to curl <IP_FROM_COMMAND>:<PORT>.
In addition to #Yuri you can simply use command:
docker ps
It shows you table info about containers:
CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS, NAMES
Then you know <CONTAINER_ID> for such commands as
docker port <CONTAINER_ID>
docker inspect <CONTAINER_ID>