Docker container is not accessible via curl or browser - docker

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

Related

"docker pull/run hello-world" behind a proxy returns "connection refused" error (non-root mode, linux mint)

Edit (kind of solved) - Just before trying something else, I've tried the same procedure (to be sure it still did not work) and it's failed (as expected). Then I've tried with the root/sudo way ("sudo docker run hello-world") and it has worked (more or less expected). Finally for unknown reason it then worked properly when invoking with the non-root way ("docker run hello-world"). It looks like it needed to go to the root/sudo way to somehow "unlock" the non-root way so that it actually uses the proxy ; weird.
I am behind a proxy. I've followed the steps on Docker doc at https://docs.docker.com/config/daemon/systemd/ as "non-root".
When I do the following,
$ docker pull hello-world
I get
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp x.x.x.x:443: connect: connection refused
(IP was changed to "x" chars).
Configuration:
Linux mint Vanessa (based on Ubuntu 22.04).
Docker version 20.10.17, build 100c701
$ systemctl --user show --property=Environment docker
returns
Environment=PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin HTTP_PROXY=http://proxy.domain.org:8080 HTTPS_PROXY=http://proxy.domain.org:8080
so it looks like proxy is actually recognized by docker (as it shows in the doc).
I am sure I can pass through the proxy with the following demonstration:
No proxy => connection refused:
$ export http_proxy= && export https_proxy=
$ curl -vv registry-1.docker.io
* Trying x.y.z.a:80...
* connect to x.y.z.a port 80 failed: Connection refused
* Trying x.y.z.b:80...
* connect to x.y.z.b port 80 failed: Connection refused
* Trying x.y.z.c:80...
* connect to x.y.z.c port 80 failed: Connection refused
* Failed to connect to registry-1.docker.io port 80 after 124 ms: Connection refused
* Closing connection 0
curl: (7) Failed to connect to registry-1.docker.io port 80 after 124 ms: Connection refused
With proxy => that's OK:
$ export http_proxy=http://proxy.domain.org:8080 && export https_proxy=http://proxy.domain.org:8080
$ curl -vv registry-1.docker.io
* Uses proxy env variable http_proxy == 'http://proxy.domain.org:8080'
* Trying x.y.z.a:8080...
* Connected to proxy.domain.org (x.y.z.a) port 8080 (#0)
> GET http://registry-1.docker.io/ HTTP/1.1
> Host: registry-1.docker.io
> User-Agent: curl/7.81.0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< content-length: 0
< location: https://registry-1.docker.io/
< Proxy-Connection: Keep-Alive
< Connection: Keep-Alive
< Age: 0
< Date: Thu, 25 Aug 2022 15:57:15 GMT
<
* Connection #0 to host proxy.domain.org left intact

Passing local proxy to docker container under Mac

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

Can't access docker container by port mapping

Host: Digital Ocean
OS: Ubuntu 18.04.4 LTS
Docker version: 19.03.12, build 48a66213fe
example 1
docker run -itd --name web -p 9000:80 php:7.2:apache
| 76a6235c907c | php:7.2-apache | "docker-php-entrypoi…" | 5 days ago | Up 5 days | 0.0.0.0:9000->80/tcp | web |
The container started successfully, but I can't access the service
curl localhost:9000
curl 0.0.0.0:9000
curl 127.0.0.1:9000
I got curl: (56) Recv failure: Connection reset by peer, even I turn off the firewall
but it works INSIDE the container
docker exec web curl -sL localhost:80
got
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<hr>
<address>Apache/2.4.38 (Debian) Server at localhost Port 80</address>
</body></html>
example 2
docker run --rm busybox ping www.google.com
got
ping: bad address 'www.google.com'
I think it's about virtual ethernet card, I installed docker via https://get.docker.com/, and already uninstalled entirely and re-install again, still the same
Make sure to open ports on the digital ocean cloud firewall. Also, check the your VPS firewall too.

Not able to connect to docker port from host machine

I'm not able to access docker port 8080 from the host machine. We have a docker container with a React application. We are able to get the landing page from inside the container but not from the host.
From the container:
root#d4947f7b1710:/# wget localhost:8080
--2019-04-01 19:38:00-- http://localhost:8080/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 492 [text/html]
Saving to: 'index.html'
index.html 100%[===============================================================================================>] 492 --.-KB/s in 0s
2019-04-01 19:38:00 (49.5 MB/s) - 'index.html' saved [492/492]
From the host:
wget localhost:8000
--2019-04-01 19:38:59-- http://localhost:8000/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8000... connected.
HTTP request sent, awaiting response... Read error (Connection reset by peer) in headers.Retrying.
Also tried wget 0.0.0.0:8000 but got the same result.
The ports seem to be mapped correctly:
docker port d4947f7b1710
8080/tcp -> 0.0.0.0:8000
Command used to start the container:
docker run -d -p 8000:8080 <docker repo>:<version>
It might be that you inverted the ports from what I see in the last part of your post

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