I'm using Docker for Mac. I have a container that run a server, for example my server is run on port 5000. I have exposed this port on Dockerfile
When my container is running, I connect to this container and check and if this server is working or not by running below command and see that it returns data (a bunch of html and javascript)
wget -d localhost:5000
Notes, I start this container and also publish port outside by command:
docker run -d -p 5000:5000 <docker_image_name>
But at docker host (is my mac and running El Capitan), I open chrome and go to address localhost:5000. It doesn't work. Just a little note, if I go to any arbitrary port such as localhost:4000 I see error message from chrome such as:
This site can’t be reached
localhost refused to connect.
But error message for localhost:5000 is:
The localhost page isn’t working
localhost didn’t send any data.
So it seems I have configured work "a little" but something wrong. Please tell me how to fix this.
Please check the program in container is listening on interface 0.0.0.0.
In container, run command:
ss -lntp
If it appears like:
LISTEN 0 128 127.0.0.1:5000 *:*
that means your web app only listen at localhost so container host cannot access to your web app. You should make your server listen at 0.0.0.0 interface by changing your web app build setting.
For example if your server is nodejs app:
var app = connect().use(connect.static('public')).listen(5000, "0.0.0.0");
If your server is web pack:
"scripts": {
"dev": "webpack-dev-server --host 0.0.0.0 --port 5000 --progress"
}
I had this problem using Docker for Mac, trying to run an Angular2 app.
I fixed the issue by changing the start script in package.json to
"scripts": {
"start": "ng serve --host 0.0.0.0"
}
Previously start was only ng serve.
Related
SO i have a service running in my localhost:80 , and localhost:8080
I need to fetch it from within a docker container
So I enter inside my docker container cli and try the following commands.
curl http://www.example.com //a famous website --> works
curl 172.17.0.1 ---> works , this is fetching my hosts localhost port 80 , its the default docker interface and resolves on the host
curl 172.17.0.1:1112 ---> I can fetch this , i have a simple express server running there returning a hello world in my local machine , it can also be curled from withing the host with a curl localhost:1112
Above as you can see im using 172.17.0.1 to connecto to my host from within my container, and not localhost, because localhost would mean the local connection of said container, and thats not what im looking for.
Now the issue comes with the following.
I crate a ssh tunnel in my port 8888 to another machine, which can only be accessed using a vpn that is running in my host. With the following command
ssh -fN myname#database.pl -L 8888:db.env.prise:80
This creates a tunnel that I can curl in my host machine localhost:8888
If I try this from within my host
curl -s http://localhost:8888/test | jq
It correctly fetches a json. SO the idea is to do something similar from within my container.
I go ahead to my container and type
curl http://172.17.0.1:8888/test
Failed to connect to 172.17.0.1 port 8888: Connection refused
And thats the eerror that I receive.
Why can I fetch every single port except that one? I suspect it might have something to do with my docker not being in the vpn ¿?
HOw can I fix this.
I have a openvpn file for the connection but thats it.
Altho I dont really think its the vpns fault, because if I Curl from my localhost with the vpn disconnected, the curl will fail but at least it attempts to curl it being stuck for a while. WHile trying to curl that port from within the docker instantly gets rejected.
It looks like you are attempting to connect from docker to a resource that you can only access via SSH on your host.
A valid solution to this problem would be to forward the port of the external machine to your machine via:
ssh -fN myname#database.pl -L 8888:db.env.prise:80
This will redirect the external port to a local port. The problem is that docker cannot access this port.
With socat, you can open a new port that listens on all interfaces and not just on local:
socat TCP-LISTEN:8889,fork,bind=0.0.0.0.0 TCP:localhost:8888
Through this port, connections will be redirected to your target machine:
8889->8888->80
I have a docker image with some ruby on rails environment built in (i.e. installing some rails gems and system packages) and I have an EXPOSE 3000 to expose the port at the end.
I ran a container with docker run -p 3000:3000 -ti <image> bash, then start the rails server. The logs are saying the web server is available on localhost:3000. I tried to connect to both the IPAddress as specified in docker inspect <id> and localhost on my host machine, but neither would be able to connect. What could be the problem here?
If your application is listening on localhost, it will only respond to requests from the container's localhost - that is, other processes inside the container.
To fix this you need to set the listen address of your server to listen to any address (usually, you specify this as 0.0.0.0). I've never used rails, but from a quick search, you should use the -b option.
So changing your ENTRYPOINT or CMD in your Dockerfile to contain -b 0.0.0.0 would probably do it.
I created a simple golang web application working on port 8080.
Docker file:
When I tried on web, I got empty response error.
Then, I opened bash of the container and found something strange.
When I did curl http://localhost:8080, I received the response but when I did same on eth0 ip, it failed.
ignore the 404. 404 means my server app is responding.
The application is accepting traffic only on localhost of the container and not accessible using docker/k8s IP.
Kindly suggest!
Did you start the container with the -p flag set to allow traffic on port 8080? (Like this: docker run -p 8080:8080 [your_image])
I've created a Dockerfile that successfully runs my Laravel 8 application locally. This is the content of the Dockerfile, located in my Laravel project root:
FROM webdevops/php-nginx:8.0-alpine
WORKDIR /app
COPY . .
RUN chmod 777 -R ./storage
ENV WEB_DOCUMENT_ROOT=/app/public
RUN composer install
I built the image and ran it locally:
docker build . -t gcr.io/my-project/my-image
docker run -p 5000:80 gcr.io/my-project/my-image
The container starts and the application runs as expected. No problems. If I shell into the container, I can see the ports that nginx is listening on:
> netstat -nlp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 49/nginx -g daemon
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 49/nginx -g daemon
As you can see the container is listening on port 80 of all network interfaces (0.0.0.0). This conforms with the CloudRun documentation and their troubleshooting guide:
https://cloud.google.com/run/docs/troubleshooting#port
A common issue is to forget to listen for incoming requests, or to
listen for incoming requests on the wrong port.
As documented in the container runtime contract, your container must
listen for incoming requests on the port that is defined by Cloud Run
and provided in the PORT environment variable.
If your container fails to listen on the expected port, the revision
health check will fail, the revision will be in an error state and the
traffic will not be routed to it.
https://cloud.google.com/run/docs/troubleshooting#listen_address
A common reason for Cloud Run services failing to start is that the
server process inside the container is configured to listen on the
localhost (127.0.0.1) address. This refers to the loopback network
interface, which is not accessible from outside the container and
therefore Cloud Run health check cannot be performed, causing the
service deployment failure.
To solve this, configure your application to start the HTTP server to
listen on all network interfaces, commonly denoted as 0.0.0.0.
From what I can tell, I have a working docker container, listening on the correct port. When I deploy to Google Cloud Run, I receive an error:
> gcloud run deploy my-service --image gcr.io/my-project/my-image --project my-project --port 80
...
Deployment failed
ERROR: (gcloud.run.deploy) Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.
In the Cloud Run Console and I can see that the service is configured with a PORT of 80 as you would expect from the --port 80 included in the deployment command. I am having trouble figuring out why this isn't working. It seems like I've done everything right.
Does anybody have any idea what might be going wrong here?
This is what I see in the deployment log on Google Cloud:
Maybe the issue is related to the third line that says ln -f -s /var/lib/nginx/logs /var/log/nginx?
It looks like I'm not the only person to have this issue with this base image:
https://github.com/webdevops/Dockerfile/issues/358
I still don't know what the problem is, but it seems to effect other people trying to use this image specifically with Cloud Run.
I am trying to run this project - https://github.com/JumboInteractiveLimited/codetest
I've downloaded the Docker tool box, and I've executed the build and run commands as mentioned on the GitHub page, but when I try to access http:localhost:8080, the page is still unavailable.
When I try to execute run again, Docker says
"$ ./run.sh
Listening on http://localhost:8080
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: driver failed programming external connectivity on endpoint quirky_mcnulty (32af4359629669ee515cbc07d8bbe14cca3237979f37262882fb0288f5d6b6b8): Bind for 0.0.0.0:8080 failed: port is already allocated."
Edit: To clarify, I get that error only when I run the 2nd time. When I ran the run command first, it didn't complain. I ran it another time just to confirm that it's running.
When I initially ran, I got the following:
$ ./run.sh
Listening on http://localhost:8080
2017/10/24 13:51:53 Waiting...
The issue seems quite clear
port is already allocated
which means that some other program is listening on port 8080.
If you are on a Linux system you can try to run
sudo lsof -i :8080
to find out what is.
Otherwise, simply use another port.
Change run.sh to replace port 8080 to 8082
#!/bin/bash
echo "Listening on http://localhost:8082"
docker run -p 8082:80 codetest
I have changes port to 8082 if the port is already in use change that port again to some other port based on your available port.
If you are on Windows
netsh interface portproxy add v4tov4 listenport=8082 listenaddress=localhost connectport=8082 connectaddress=192.168.99.100(IP of the Docker)
Here is the helping discussion on port farwarding in windows with docker Solution for Windows hosts