Unable to run Golang application on Docker - docker

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

Related

Ports are not available when attempting to run Node Red in Docker

When I am trying to run the Docker container for Node Red using the following command:
docker run -p 1880:1880 --name mynodered nodered/node-red
I get the following error:
c:\program files\docker\docker\resources\bin\docker.exe: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:1880: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
I have tried using netstat to find anything that's using up the port and I've found nothing. I've also tried to open up the ports in Windows Firewall and this still errors out.
Is there any other way to run Node Red on Windows Docker with port 1880?
It's a know issue on Windows with some workaround available.
You can block HNS to reserve high ports with this registry key:
reg add HKLM\SYSTEM\CurrentControlSet\Services\hns\State /v EnableExcludedPortRange /d 0 /f
And reboot.
For more details, you can check this github issue.
After much searching, I've found an answer to this. The port is being reserved by Hyper-V, so you will need to remove it, add the port to exclusion list, then readd Hyper-V.
My solution is based on this answer:
https://stackoverflow.com/a/59044246/3866585
You don't need to run node-red on that particular port if it's reserved.
Try something like this:
docker run -dit -p 8880:1880 --name mynodered nodered/node-red
Then navigate to:
http://localhost:8880

Connect to selenium inside docker container

I trying connect to selenium, but I getting error:
Failed to connect to localhost port 4444: Connection refused
What is wrong? It is works normally in browser: http://localhost:4444/wd/hub/ and I see selenium.
I also tried connect to different port (eg. elastic) and it is these same.
You havent provided anough info on how your Dockerfile looks like and what command you're running to start the container. Please do that.
In any case here are some important points.
First in your dockerfile I hope you have
EXPOSE 4444
Secondly, if you just deploy your container using the docker run command, it will not be available to your localhost UNLESS you expose the required ports. Run your container with the below command :
docker run -p 4444:4444 -itd <IMAGE-ID>
Also make sure that the firewalld/iptables services on your machine are correctly configured to allow access to 4444

Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error Permission denied

I am running the latest Docker CE, 17.09, under Windows 10 Pro, and using two different examples am getting Permission denied.
Docker site example:
docker run -d -p 80:80 --name webserver nginx
AWS site Docker example:
docker run -p 80:80 hello-world
both returned the same error.
docker: Error response from daemon: driver failed programming external connectivity on endpoint XXXXX: Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error Permission denied.
I solved my issue on Windows 10 Pro, turned out I had the World Wide Web Publishing Service turned on somehow. Took me a while to find that, after noting via netstat -a -n that I had a :80 listener somewhere/somehow. Silly me. Shut it down, and I was fine with port 80.
Change the port using these commands as follow:
docker container ls //show the container infos, note the ports info.
docker stop webserver
docker rm webserver //shut down currently webserver
docker run -d -p 8080:80 --name webserver nginx (or 8000:80)
Finally, let's input localhost:8080 to show whether the connection is successful in the browser.
The problem is general-use ports like 80, 443, 22, .. (in general ports < 1024) are system-protected so you need privileges to use them, here it'll be enough to be a system administrator and execute command as a administrator.
If it doesn't have to be :80 try using other port, like :8080, if that doesn't help and the error doesn't change, the problem goes deeper.
On macOS Mojave Version 10.14.2 this command worked for me:
sudo apachectl stop
Before executing this command, run
sudo lsof -i -P | grep "LISTEN"
and check if httpd is the identifier of the listener on :80 e.g.:
If it is, then it's actually the Mac apache that causes the problem.
The First course of action that you should take is to run the command:
netstat -aon | findstr [port#]
This will tell you if a process is running on the given port. If that is the case then you can kill the process with the command:
taskkill /PID [PID] /F
This will kill the process using that port. You will then be able to bind a new process to the port.
I also had come across a time when netstat -aon did not return that a process was running for a port that I desired to use but it certianly had a process running on it was wasn't allowing me to run a new process on the port. I was able to remedy the problem with the following:
Start Windows in Safe Mode with Networking
In powershell/cmd run the command:
netsh int ipv4 add excludedportrange protocol=tcp startport=[PORT] numberofports=1
This will reserve the port so when you boot back into normal windows mode no application will steal the port before you can use it.
The reason I got this error was because the port was already in use. Changed to a different port and I no longer received this error.
On Windows 10 Pro running Docker command from a CMD Window with As Administrator, I still have the issues (as per #mikael-chudinov above).
I really want to use port 80 so the other answers are not suitable for me.
Please see this blog post by Jens at www.jens79.de
From powershell, run the command:
Get-NetTCPConnection -LocalPort 80 | Format-List
This for me showed up a single process with pid = 4
In System monitor this is the "System" process, but as per the article listed above, it is actually IIS running as "World Wide Web Publishing Service".
Assuming that you don't need IIS running, in the Windows Services console, Stop and Disable "World Wide Web Publishing Service", then try again.
The port is in use by VisualStudio without debugging. Close VS then reopen.
I recently came across this issue while trying to load up a docker environment to maintain an old project. In my case, the default instance of Apache was running on my Mac after a recent OS update, and needed to be shut down before port 80 was available. You can shut it down with this command:
sudo /usr/sbin/apachectl stop
If you're still having trouble, you could use the following command to see the PIDs of what's running on a given port (in this case, 80):
lsof -t -i :80
You can attempt to shut down whatever is running on those ports with the kill command; just be sure you aren't going to kill anything important!
kill $(lsof -t -i :80)
This helped me. The port mentioned in the error message indeed was within one of reserved port ranges: Windows can't bind to port above 49690
Had same issue, my container just would not start and display following error msg when trying to start the container:
Error response from daemon: driver failed programming external connectivity on endpoint ..... Error starting userland proxy: Bind for 0.0.0.0:1521: unexpected error Permission denied.
with following command for starting a oracle container:
docker run -d -p 1521:1521 ...
For me i think its the result of a uninstalled oracle instance that is not properly uninstalled. Port still used or something. But simply changing to another port fixed the issue as shown below:
docker run -d -p 1523:1521 ...
Listening on a privileged port (lower then 1024) requires special capabilities from the kernel.
You have two options:
1 ) Run your container as root - don't do it.
2 ) Give the container the relevant capability only - in your case its the NET_BIND_SERVICE capability which bind a socket to privileged ports.
So if the image you use is running as root by default - make sure first to create a non root user and attach it to a group - add this line to your Dockerfile:
RUN set -x \
&& addgroup --system --gid 101 nginx \
&& adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx
And run the container with net_bind_service only:
docker run -it -p 8080:80 --cap-drop all --cap-add net_bind_service <image-name>:<tag>
I also have the same issue. If a proxy is already installed on your system, then the container port is surrounded by a proxy and you need to use a proxy to run the container once and you will not need to do this for the next time.
The problem is you are not having permission to run image in port 80. To do so add --user root in your docker run command. This will provide root privileges and it will run.
Verify if the nginx in the host machine is started and stop it.
sudo service nginx stop
1,docker run -p 80:80 nginx
If command 1 does’t work then try command 2.
2, docker run -d -p 8080:80 --name webserver nginx
After that go to browser and type localhost:8080
The above command will solve.

docker: driver failed programming external connectivity on endpoint webserver

I am trying to run a docker example following this documentation
This is my command:
docker run -d -p 80:80 --name webserver nginx
But I get this error:
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (bd57efb73c738e3b271db180ffbee0a56cae86c8193242fbc02ea805101df21e): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).
How do I fix this?
From your error message, the EADDRINUSE indicates port 80 is already in use on either the docker VM or possibly directly on your laptop. You can either stop whatever is running on that port, or change the port used in your Docker, command. To change to the external port 8080, use:
docker run -d -p 8080:80 --name webserver nginx
If you are the port i not in use, try restarting docker. That usually works for me.
I had the same issue with one of my containers. I tried everything but when nothing worked, I tried the following and launched the container again with success
sudo service docker stop
sudo rm /var/lib/docker/network/files/local-kv.db
sudo service docker start
Try restarting the docker service. It works 99% of the time.
service docker restart
If that didn't work as expected, try restarting your pc and then restarting the docker service using above command.
If none of the above worked try changing the exposed port to another unused port that should work.
docker run -d -p 81:80 --name webserver nginx
Note :- 81 is the port on your host and 80 is the port on your docker container
For the first time, when i made a docker simple web app, i also faced same problem.
Simply you can try the following steps to resolve the problem and also able to understand the reason why you had faced the problem in details.
Step-1: check all the running containers using the command:
docker ps
Step-2: Find out the container id of the container which is running on the same port, you are trying to reach.
Step-3: Stop the container which one is running on the same port using this command:
docker stop <container id>
Step-4: Again build the container:
docker build -t DockerID/projectName .
Step-5: Again try to run your container on the same port using port mapping.
docker run -p 8080:8080 DockerID/projectName
Try this command:
sudo service docker restart
If it does not help, restart your server.
Stop all the running containers docker ps -a -q then
Stop the Docker on your machine & restart it.
Recently this problem started to happen a lot on Windows. You can try restarting docker or you can manually stop docker before Windows shutdown - docker starts cleanly on reboot. On 7/24/2018 docker issue is open and further details can be found at https://github.com/docker/for-win/issues/1967
Check what's on port 80 right now - sudo ss -tulpn | grep :80
You may have apache2 running.
You can check it - sudo service apache2 status
If so - sudo service apache2 statop
If you tried all above solutions and still having issues, you can kill LISTEN ports manually as below for Linux users
sudo lsof -i -P -n | grep LISTEN
sudo kill -9 <process_pid> (ex. sudo kill -9 28563 28575 28719 28804)
In my case, port 80 is the default port for the web server and therefore it is protected. I changed the bind to port 60:8080 to ensure no deeper issues. Changing the bind to a different port allows me to execute the docker run and hit it in the browser at http://ip:60
I had same problem with same error.
As long as I had a local nginx installed in my computer, running another nginx through the container made conflict in port :80.
Simply I tried to stop the service of my local installed nginx as below:
sudo service nginx stop
Then after, I could run nginx by docker-compose up -d without any problem:
Creating MyWebServer ... done
Creating mongo ... done
Creating redis ... done
For me, a simple
ddev poweroff
fixed this.
If this case is with Redis: remove the ports - ... in the docker-compose file and let it assign by itself. or change the port mapping in the host from 6379:6379 to 6378:6379 that worked for me.
windows users: docker description
On Windows systems, CTRL+C does not stop the container. So, first type
CTRL+C to get the prompt back (or open another shell), then type
docker container ls to list the running containers, followed by docker
container stop to stop the container.
Otherwise, you get an error response from the daemon when you try to
re-run the container in the next step.
I had the same problem, I thought with CTRL+C stoped the container but it was not the case, any af the answer above works because they all stop containers, restarting docker or stoping container explicity.
I prefer:
docker container ls #list containers running
docker stop [container id] #replace [container id] with the container id running
This seems to be an incompatibility problem with windows "fast-boot" as described here: (just restart the docker service) and it may work.
https://github.com/docker/for-win/issues/2722
This is caused by an incompatibility with Docker and fastboot. You can either make sure you stop all containers before shutting Windows down or you can disable fastboot in Windows' power settings by doing the following:
CTRL+R > "powercfg.cpl" > "Choose what the power buttons do" > "Change settings that are currently unavailable" > Deselect "Turn on fast start-up"
You can also disable fastboot with a single command in powershell if you're comfortable doing so:
Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power\' -Name HiberbootEnabled -Value 0
If you are using WSL, after i tried all above and still it doesn't work, i tried to restart the WSL from Powershell with admin privileges and shutdown command:
wsl --shutdown
That worked for me.

Connection refused when try to connect http server in docker daemon container

I am using boot2docker. I run one image at the daemon mode which starts grunt server at port 3000. This is the command I used to start it up.
That image has already exposed port 3000
docker run -d -P --name dummy image_name grunt server
docker ps
3af4ba19c539 image_name:latest "grunt server" 54 minutes ago Up 54 minutes 0.0.0.0:45000->3000/tcp dummy
and then run into the same container to "curl" the web server.
docker exec -it 3af4ba19c539 /bin/bash
curl localhost:3000
It gets the html.
However, when I try to connect it in my mac pc. It said "Connection refused."
curl $(boot2docker ip):45000
//curl: (7) Failed connect to 192.168.59.103:45000; Connection refused
I try to solve this problem by using VBoxManage, but it is not working either
VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port45000,tcp,,45000,,45000"
May I know how to solve this problem. Many thanks in advance
I need to see the source of your application to be sure, but I'm willing to bet you've bound to the local loopback interface (127.0.0.1 or localhost) in your application. If you instead bind to 0.0.0.0 to listen to all interfaces, you should find it is accessible from the outside.

Resources