I have this scheme for a remote connection to docker app.
ContainerA Ip: 172.17.0.2
ContainerB Ip: 172.17.0.3
vncserver in the containerA run on port 5901 and exposed to others.
containerA[vncserver] <-- containerB[virtualGL + App]
ContainerB has ENTRYPOINT ["/opt/VirtualGL/vglrun"]
Then, I run: docker exec containerB -d 172.17.0.2:5901 App
But it fails with:
fail to open Display 172.17.0.2:5901
How do I to communicate virtualGL with vncserver?
Related
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.
I have many containers on my server, I need to access all containers by the name(not IP).
and of course, I can ping containers by IP address.
problem is I can't ping them by hostname or name.
also, I don't using docker-compose. I use docker file and docker restapi
Option A: run a DNS proxy server container
Here is a DNS proxy server project that can do this: https://github.com/mageddo/dns-proxy-server
First, you need to start the DNS proxy server:
docker run --rm --hostname dns.mageddo -v /var/run/docker.sock:/var/run/docker.sock -v /etc/resolv.conf:/etc/resolv.conf defreitas/dns-proxy-server
Then, run a dummy container and assign it a --hostname for testing purpose:
docker run -d --hostname=this-can-be-resolved-from-host nginx
Finally, try to resolve/ping/curl the name you assigned to the nginx container in the previous step, from your host machine:
neo#neo-desktop:~$ nslookup this-can-be-resolved-from-host
Server: 172.17.0.4
Address: 172.17.0.4#53
Non-authoritative answer:
Name: this-can-be-resolved-from-host
Address: 172.17.0.3
Name: this-can-be-resolved-from-host
Address: 172.17.0.3
neo#neo-desktop:~$ ping this-can-be-resolved-from-host
PING this-can-be-resolved-from-host (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3 (172.17.0.3): icmp_seq=1 ttl=64 time=0.032 ms
neo#neo-desktop:~$ curl this-can-be-resolved-from-host
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
[...]
Option B: Run an injector that adds the container names directly in the hosts file, on the docker host:
(solution found by the OP #Tokyo Developer)
Here is a simple "etc/hosts" file injection tool: https://github.com/dvddarias/docker-hoster
Run the injector container:
docker run -d \
-v /var/run/docker.sock:/tmp/docker.sock \
-v /etc/hosts:/tmp/hosts \
dvdarias/docker-hoster
Run a dummy container and assign it a --hostname for testing purpose:
docker run -d --hostname=this-can-be-resolved-from-host nginx
Try to resolve the hostname AND the container name assigned to the nginx container in the previous step, from your host machine:
nslookup this-can-be-resolved-from-host
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: this-can-be-resolved-from-host
Address: 172.17.0.3
nslookup keen_lamarr
Server: 127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: keen_lamarr
Address: 172.17.0.3
Following the tutorial on https://docs.docker.com/get-started/part2/.
I start my docker container with docker run -p 4000:80 friendlyhello
and see
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8088/ (Press CTRL+C to quit)
But it's inaccessible from the expected path of localhost:4000.
$ curl http://localhost:4000/
curl: (7) Failed to connect to localhost port 4000: Connection refused
$ curl http://127.0.0.1:4000/
curl: (7) Failed to connect to 127.0.0.1 port 4000: Connection refused
Okay, so maybe it's not on my local host. Getting the container ID I retrieve the IP with
docker inspect --format '{{ .NetworkSettings.IPAddress }}' 7e5bace5f69c
and it returns 172.17.0.2 but no luck! curl continues to give the same responses. I can confirm something is running on 4000....
lsof -i :4000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 94812 travis 18u IPv6 0x7516cbae76f408b5 0t0 TCP *:terabase (LISTEN)
I'm pulling my hair out on this. I've read through the troubleshooting guide and can confirm
* not on a proxy
* don't use a custom dns
* I'm having issues connecting to docker, not docker connecting to my pip server.
Running the app.py with python app.py the server starts and I'm able to hit it. What am I missing?
Did you accidentally put port=8088 at the bottom of your app.py file? When you are running this the last line of your output is saying that your python app is exposed on port 8088 not 80.
To confirm you can run either modify the app.py file and rebuild the image, or alternatively you could run: docker run -p 4000:8088 friendlyhello which would map your local port 4000 to 8088 in the container.
Try to run it using:
docker run -p 4000:8088 friendlyhello
As you can see from the logs, your app starts on port 8088, but you connect 4000 to 80 where on 80, nothing is actually listening.
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>
Running a Jenkins image in my container which is bound to the host port 9090
sudo docker run -itd -p 9090:8080 -p 50000:50000 --name=myjenkins -t jenkins-custom /bin/bash
The output of running $docker port myjenkins
50000/tcp -> 0.0.0.0:50000
8080/tcp -> 0.0.0.0:9090
I can also see the binding from the host perspective ps -Af | grep proxy
root 15314 15194 0 17:52 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 50000 -container-ip 172.17.0.2 -container-port 50000
root 15325 15194 0 17:52 ? 00:00:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9090 -container-ip 172.17.0.2 -container-port 8080
After starting my jenkins server i try connect to the container using the host ip and the forwarded port (9090).
I'm new to Docker so may have missed something however would appreciate suggestions
Update: including dockerfile
From local-artifiactory/jenkinsci/jenkins:2.9
ENV java_opts="-Xmx8192m"
This is not an answer to this specific question. It is a possible answer to "port mapping doesn't work"
I've been caught by this twice.
The image name must come last when creating a container from the command line
This syntax:
docker run --name MyContainer MyImage -p 8080:80
will create container MyContainer from MyImage without issue
But the -p 8080:80 part will be silently ignored and your port mapping won't work
This syntax will work - you'll see exactly the same outcome except that port mapping will actually work.
docker run --name MyContainer -p 8080:80 MyImage
Same for this:
docker run MyImage --name MyContainer
This will create a container from MyImage but it won't give it the explicit name, it'll assign a random name
I hope this saves someone some time.
Port binding/publishing in docker is actually publishing container's port to docker-machine's, instead of to localhost's. For example, with
docker run -p 9090:8080 jenkins
you will be able to access the service by curl <your-docker-machine>:9090, NOT curl localhost:9090 or curl 127.0.0.1:9090
To get your docker-machine's IP, do: docker-machine ls and check the URL
The problem is that no service is running at those ports. The only process running is /bin/bash (as specified in the end of the line). You must start Jenkins inside the container.