Passing local proxy to docker container under Mac - 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

Related

Docker container is not accessible via curl or browser

I used following command to create a nginx container.
$ docker run -it -d --name test-nginx -p 8090:8091 nginx
and it seems to be up and running fine
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e36f30ce7854 nginx "/docker-entrypoint.…" About an hour ago Up About an hour 80/tcp, 0.0.0.0:8090->8091/tcp, :::8090->8091/tcp test-nginx
But I'm not able to access the container via browser or curl command. I get the following error.
$ curl localhost
curl: (7) Failed connect to localhost:80; Connection refused
$ curl localhost:8090
curl: (56) Recv failure: Connection reset by peer
curl localhost:8091
curl: (7) Failed connect to localhost:8091; Connection refused
$ curl 10.57.8.115
curl: (7) Failed connect to 10.57.8.115:80; Connection refused
$ curl 10.57.8.115:8090
curl: (7) Failed connect to 10.57.8.115:8090; Connection refused
$ curl 10.57.8.115:8091
curl: (7) Failed connect to 10.57.8.115:8091; Connection refused
Could anyone please help me what is the issue and when I do
$ curl localhost:8090
It gives the following error?
curl: (56) Recv failure: Connection reset by peer
nginx listens on port 80 within the container, so that is the port you need to expose on the host. You are exposing port 8091. So your command should be:
docker run -it -d --name test-nginx -p 8091:80 nginx
to expose container port 80 on local host port 8091. Your curl command should then run successfully:
$ curl -I localhost:8091
HTTP/1.1 200 OK
Server: nginx/1.23.1
Date: Fri, 07 Oct 2022 07:29:43 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 19 Jul 2022 14:05:27 GMT
Connection: keep-alive
ETag: "62d6ba27-267"
Accept-Ranges: bytes

Operation timed out when connecting to Mailhog in Docker container

I started mailhog in container: docker run --rm -ti -p 8025:8025 -p 1025:1025 mailhog/mailhog. Web UI works, but connection fails:
curl smtp://172.17.0.2:1025 --mail-from a#b.com --mail-rcpt c#d.com
curl: (28) Failed to connect to 172.17.0.2 port 1025 after 31641 ms: Operation timed out
172.17.0.2 is container IP address, i'm using Docker Desktop for Mac. Why connection is not established?
I solved this problem by connecting mailhog container to a network defined in docker-compose.yml.

Docker: ssh -L to docker container - connection refused

I'm having problems to get my ssh tunnel working for my container in a docker swarm cluster.
ssh connection on my local machine:
ssh -L 7180:test.XXX:7180 user#XXX
In my Dockerfile on the remote machine:
EXPOSE 7180
Container start:
docker -H test:2379 --tlsverify run -d -p 7180:7180 --net=my-net
I tried to connect in Firefox via:
localhost:7180
Unfortunately the connection gets refused on the remote machine:
channel 3: open failed: connect failed: Connection refused
"docker container ls" prints following for the ports:
xxx:7180->7180/tcp
Inside my container "netstat -ntlp | grep LISTEN" prints:
tcp 0 0 0.0.0.0:7180 0.0.0.0:* LISTEN -
I'm new to this but after all what I've read so far this should actually work. I'm using "--net=my-net" because I want to setup my own network later. I had the same issue with "--net=host". What am I doing wrong?
The ssh command should be:
ssh -L 7180:127.0.0.1:7180 user#XXX
And then from your browser, you would go to:
http://127.0.0.1:7180
I've avoided using "localhost" because some machines map this to IPv6 even if you don't have IPv6 configured.
When testing this tunnel, make sure your application is listening on the remote server by doing an ssh to that server and run a curl command directly on the server to 127.0.0.1:7180. If it doesn't work there, you would repeat your debugging with netstat inside the container and verifying the port is published in thedocker ps` output.
I got it working with
ssh -D localhost:7180 -f -C -q -N user#XXX
and using
xxx:7180
in my browser (instead of localhost).
localhost and --net=host did not work for me with ssh -L.

curl (56) Recv failure: Connection reset by peer - when hitting docker container

getting this error while curl the application ip
curl (56) Recv failure: Connection reset by peer - when hitting docker container
Do a small check by running:
docker run --network host -d <image>
if curl works well with this setting, please make sure that:
You're mapping the host port to the container's port correctly:
docker run -p host_port:container_port <image>
Your service application (running in the container) is running on localhost or 0.0.0.0 and not something like 127.0.0.1
I GOT the same error
umesh#ubuntu:~/projects1$ curl -i localhost:49161
curl: (56) Recv failure: Connection reset by peer
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
in my case it was due wrong port no
|---MY Projects--my working folder
--------|Dockerfile ---port defined 8080
--------|index.js-----port defined 3000
--------|package.json
then i was running ::::
docker run -p 49160:8080 -d umesh1/node-web-app1
so as the application was running in port 3000 in index.js it was not able to connect to the application got the error as u were getting
So TO SOLVE THE PROBLEM
deleted the last container/image that was created my worong port
just change the port no of INDEX.JS
|---MY Projects--my working folder
--------|Dockerfile ---port defined 8080
--------|index.js-----port defined 8080
--------|package.json
then build the new image
docker build -t umesh1/node-web-app1 .
running the image in daemon mode with exposed port
docker run -p 49160:8080 -d umesh1/node-web-app1
THUS MY APPLICATION WAS RUNNING without any error listing on port 49161
I have same when bind to port that is not lissened by any service inside container.
So check -p option
-p 9200:9265
-p <port in container>:<port in host os to be binded to>

Docker swarm and service discovery

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 [...]

Resources