cannot reach web app from docker host (not docker-machine) - docker

I have a simple web app container running on docker engine for mac (v.1.12.5) using the following:
docker run --rm -p 80:8089 test-app
I've checked my container's IP under Networks > bridge from the following:
docker inspect $(docker ps -l --format "{{.ID}}")
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "f53f1b93aa0f2fda186498d30e7f6e5b97ba952d1b6fe442663ac6025fd74ce3",
"EndpointID": "178937cf211c2360d9f9c594891985637d1d82a334a40b1b46d3acb2ea8aaf20",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2", // <- use this?
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
As far as I understand, I am running my web app container on my docker engine directly on my laptop (not via docker-machine). At this point, I'm not so much concerned with making it work rather than understanding.
My container has an assigned IP 172.17.0.2 which I've pasted above and I've mapped my web app container (with an EXPOSE 80) to port 8089 via the docker run -p flag.
I'm under the impression that I should be able to reach my web app at http:// 172.17.0.2:8089 but I just get no response. Why?

If the process in the container listens on port 80, your -p flag should be the other way round -p 8089:80. The service can then be reached at localhost:8089.

Related

TCP server started but connection refused inside a container

I have a golang application which starts a TCP server on port 8080. Every thing works fine when I run the app native.
However when I run it as a container, I am unable to even telnet to the port from within the container itself.
docker ps
9bb08785b728 dp_local "/bin/dragonpit-linux" 8 seconds ago Up 7 seconds 8080-8081/tcp youthful_villani
docker exec -it youthful_villani sh
/ # telnet localhost 8080
telnet: can't connect to remote host (127.0.0.1): Connection refused
Note: used 0.0.0.0 as well as 127.0.0.1 in place of localhost
TCP Server starting code
var err error
var lc net.ListenConfig
th.listener, err = lc.Listen(ctx, "tcp", "0.0.0.0:8080")
if err != nil {
return err
}
clog.Info(ctx, "tcp protocol listening", "listenAddr", th.addr)
I hard-coded the address to see whats the issue.
My Dockerfile
FROM golang:1.18.0 as builder
RUN mkdir -p /build/
ADD . /build
WORKDIR /build
RUN CGO_ENABLED=0 GOOS=linux go build -o tcp_server
FROM alpine:latest
EXPOSE 8080 8081
RUN mkdir -p /server/config
ADD config /server/config/
ENV SMC_PATH /
COPY --from=builder /build/tcp_server /bin/
RUN apk update
RUN apk add busybox-extras
ENTRYPOINT ["/bin/tcp_server"]
Output of docker-inspect
"NetworkSettings": {
"Bridge": "",
"SandboxID": "a70f476a8a7376b1e5a935b67170145f2222e059c5b2a1a63da50519a491babf",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"8080/tcp": null,
"8081/tcp": null
},
"SandboxKey": "/var/run/docker/netns/a70f476a8a73",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "7b6b9d0d5f83b8136919ac0f765167f6d380a8d836f460a0243bedeb3489a013",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "16563fdda1d5059bb6e2800455f2e87ac8d02e040386eae595a215692e849d76",
"EndpointID": "7b6b9d0d5f83b8136919ac0f765167f6d380a8d836f460a0243bedeb3489a013",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
Docker running command and starting logs
docker run dp_local
25T14:59:46.367075600Z","caller":"build/main.go:24","msg":"Starting listening","listenAddr":"0.0.0.0:8080"
Edit:
I just printed out the Addr().String() of TCP Listener, I got this
{"level":"info","ts":"2022-04-25T15:44:28.952095700Z","caller":"server/tcp.go:65","msg":"[::]:8080"}
Answering my question here. It was actually a TCP parameter which was set incorrectly and caused issues. The culprit was MTU. For reference: https://www.baeldung.com/cs/tcp-max-packet-size#:~:text=The%20maximum%20size%20of%20a,size%20should%20never%20exceed%20MTU.
Two Assumptions based on your question
You want to expose ports 8080 and 8081
EXPOSE 8080 8081
2. You are running the docker image and the client on same machine
In that case you need to bind the Docker container ports to ports on an interface on the local machine. Let's use localhost. You docker run command should look like
docker run -p 127.0.0.1:8080:8080/tcp -p 127.0.0.1:8081:8081/tcp dp_local
This will bind container ports 8080 to 8080 and 8081 to 8081 on localhost of local machine.
Read more here

Jenkins on docker won't run on port 8080

I have 'docker desktop' installed on my windows 10.
so, I pulled in Jenkins image from docker hub and then run the commands:
docker pull jenkins/jenkins
docker volume create jenkins_home
docker run --name jenkins -p 8080:8000 -p 50000:50000 -v C:/Users/myusername/Documents/jenkins_home:/var/jenkins_home jenkins/jenkins
On console, everything was ok, and get the password for the admin user.
So after that I run
docker start jenkins
and then
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
36683f39dd31 jenkins/jenkins "/sbin/tini -- /usr/…" 6 minutes ago Up 2 minutes 8080/tcp, 0.0.0.0:50000->50000/tcp, 0.0.0.0:8080->8000/tcp jenkins
Now, I need to log into http://localhost:8080/ port to view the Jenkins web app. But did not bring up Jenkins app. I also tried using docker inspect to get the container's ip, but port 8080 didn't work on those ips as well.
"NetworkSettings": {
"Bridge": "",
"SandboxID": "19504b4695ca4dfc9c4af41c9a7ef90115004af07d0099ffed33f4838155cddb",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"50000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "50000"
}
],
"8000/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
],
"8080/tcp": null
},
"SandboxKey": "/var/run/docker/netns/19504b4695ca",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "f1938dad37524b58d3146f8bfffa4964687d1946ab97b3ae7f0105ced3f64ddf",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"Aliases": null,
"NetworkID": "b285258a51bc4877fa9ff8a1928eced061f61a4f92f54a5aa756a118e0f1cb7b",
"EndpointID": "f1938dad37524b58d3146f8bfffa4964687d1946ab97b3ae7f0105ced3f64ddf",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
NOTE: Before running jenkins, I made sure the port wasn't busy.
netstat -aon | findstr 8080
After kenkins running, the command shows me
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 25076
TCP [::]:8080 [::]:0 LISTENING 25076
If I find the process to use this port, I got this
tasklist | findstr 25076
com.docker.backend.exe 25076 Console 2 22.664 K
so, Which ip address do I use to see the Jenkins app that is running in the container? and why the localhost on port 8080 doen't work ?

Docker - connect from HOST to container

I am using Docker for Windows with created bridge network:
"bridge":"none" (daemon.json)
docker network create --subnet 192.168.23.1/24 --gateway 192.168.23.1 --driver bridge my-network
... and container with Jenkins image.
When I configure connection between Jenkins (container) and Gitlab ("internet") everything is working fine. But when I am creating Webhook in Gitlab I have to enter URL of Jenkins. I was trying with localhost and IP obtained from IPAddress property:
"Networks": {
"my-network": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"jenkins",
"dff5dcb7c95a"
],
"NetworkID": "xxx",
"EndpointID": "yyy",
"Gateway": "192.168.23.1",
"IPAddress": "192.168.23.2",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "zzz",
"DriverOpts": null
}
}
.. but both options have been not working.
Question: How to determine correct URL?
How to connect from HOST to my container? Is it correct approach? What issues should I know to resolve following problems in the future?
Thanks for help :)
If you are running your Gitlab-instance also in a Docker-container you just need to add the Gitlab-container to the same Docker-network.
If your Gitlab-instance is really in the internet, you can not solve this with localhost or any local IP-adress. You need to:
find out your public IP-adress, maybe use dynDNS to get a fix domain if you have a dynamic IP
open a port on your router and configure your firewall
open a port on your local windows firewall
need to find out on which port jenkins is waiting for the webhooks from GitLab
map this port to the docker-container by using
--p <docker-internal-port>:<docker-external-port>
If you would provide some more information about your network infrastruture, the answer could be clearer.

Docker Toolbox for Windows, Container is not accesible on the host

I am new and working on Docker on my Windows Machine. I got toolbox installed on my machine well and ran a container, see below:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cea8e6cf92b5 seqvence/static-site "/bin/sh -c 'cd /usr…" 21 minutes ago Up 21 minutes 0.0.0.0:32769->80/tcp, 0.0.0.0:32768->443/tcp competent_goodall
Now, this is a Linux container running on a Oracle VM on my windows machine. After this I expect to do a http://172.17.0.2:32769 on my windows machine and get a web page running on Ngnix server.
Here is the container inspect:
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "81d64a885b80a000f3b91e9959acf125b170b7acb11a918bf77bf7fa3fea3ae1",
"EndpointID": "6cf13c7007539f0b31c6d8da52844477f13e1debd84a8f3e2ec63ee140e90014",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
I am not sure if any more details would be needed to understand the problem, so please feel free to let me know.
I think you should try either of the following,
http://localhost:32769
http://(ipv4 of your windows machine):32769

Run netflixoss Docker on Windows 8.1

I have installed docker-toolbox v1.12 locally on a Windows 8.1 laptop.
As suggested here I have run docker run -d --name exhibitor netflixoss/exhibitor:1.5.2. This has pulled all the images in my Docker VM "home". docker inspect <<container-id>> (container id obtained from docker ps command) reveals my Network Settings as below.
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c1a16c1704f76b2e2a35b2ae6a18780aaedac078cceb005b419cafb405b1e3b2",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"2181/tcp": null,
"2888/tcp": null,
"3888/tcp": null,
"8080/tcp": null
},
"SandboxKey": "/var/run/docker/netns/c1a16c1704f7",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "3e19d6c6eeb2e7c9dbb9b357ac4ecc9515bdf391df6688f17420bb9443ce3d22",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "85b5af82cb891978b6d3272f622c747fa68546d0401a24e85c9d42f7644ea2d4",
"EndpointID": "3e19d6c6eeb2e7c9dbb9b357ac4ecc9515bdf391df6688f17420bb9443ce3d22",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02"
}
}
}
I'm trying to invoke the running Docker container from Windows host using "http://172.17.0.2:8080/exhibitor/v1/ui/index.html". But that doesn't seem to work. docker ps suggests the container is up
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
1a849df14320 netflixoss/exhibitor:1.5.2 "java -jar exhibitor-" About an hour ago Up About an hour 2181/tcp, 2888/tcp, 3888/tcp, 8080/t
cp exhibitor
Also I can connect to the container using docker attach 1a849df14320 and see the following log entries time-to-time
INFO com.netflix.exhibitor.core.activity.ActivityLog Cleanup task completed [pool-2-thread-93]
I'm a complete newbie with Docker.
You have not exposed the port to the host.
docker ps -a should give output similar to:
0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp
This shows port 1234 on the host is mapped to 9876 in the container.
Your docker ps output has no port mappings. You should do:
docker run .......... -p 8080:8080
You can always use the -P flag too (if you expose the port in the Dockerfile) but the above solution is the quickest.

Resources