Deallocate a port on mac for zookeeper - docker

I know this might have asked before. But I have been struggling with this for last 2 hours.
I am following a tutorial on apache kafka and trying to run this command to run a docker container:
docker run --rm -p 2181:2181 -p 3030:3030 -p 8081-8083:8081-8083 -p 9581-9585:9581-9585 -p 9092:9092 -e ADV_HOST=192.168.99.100 landoop/fast-data-dev:latest
however I am getting this error:
ocker: Error response from daemon: driver failed programming external connectivity on endpoint friendly_austin
(7fe43e4a4081d4ac072a8fbb9582b9456eb71e488fe9a21c358a916061709005): Error starting userland proxy: Bind for 0.0.0.0:2181 failed: port is already allocated.
I am aware this has to do with the allocated port 2181.
So i ran
lsof -i TCP:2181
I got the following pid:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 79831 omkar 27u IPv6 0xa390d90220637c69 0t0 TCP *:eforward (LISTEN)
However, I dont understand how can i free this port, or deallocate it? DO i even need to do it?
Help will be much appreciated.

This is a docker error - you cannot map port 2181 of your container as your host already use it
Simply modify this binding:
docker run --rm -p 2182:2181 -p 3030:3030 -p 8081-8083:8081-8083 -p 9581-9585:9581-9585 -p 9092:9092 -e ADV_HOST=192.168.99.100 landoop/fast-data-dev:latest
note the -p 2182:2181
I used 2182 here, you can use an other one
If you ever need to use zookeeper adress, this will be via :2182

Related

Port issue with Docker for Windows

I'm trying to follow the beginner tutorial at training.play-with-docker.com. At Task 2, step 6, I do the following and get the error as below:
PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 80:80 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0
d39667ed1deafc382890f312507ae535c3ab2804907d4ae495caaed1f9c2b2e1
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: driver failed programming external connectivity on endpoint linux_tweet_app (a819223be5469f4e727daefaff3e82eb68eb0674e4a46ee1a32e703ce4bd384d): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
I am using Docker Desktop on a Win10 machine locally. I've tried resetting Docker as suggested here. Error persists. Since something else must be using port 80, I should be able to avoid the error by using a different port, right?
PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 1337:1337 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0
Right! docker ps now confirms the container is running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b700df12c2d1 dzemens/linux_tweet_app:1.0 "nginx -g 'daemon of…" About a minute ago Up About a minute 80/tcp, 443/tcp, 0.0.0.0:1337->1337/tcp linux_tweet_app
But when I try to view the webpage that the tutorial sends me to, I get an error in the browser.
I'm not sure how the link is dynamically generated but it looks something like this:
http://ip172-18-0-32-blsfgt2d7o0g00epuqi0-80.direct.labs.play-with-docker.com/
Browser error as below:
The proxy could not connect to the destination in time.
URL: http://ip172-18-0-32-blsfgt2d7o0g00epuqi0-80.direct.labs.play-with-docker.com/
Failure Description: :errno: 104 - 'Connection reset by peer' on socketfd -1:server state 7:state 9:Application response 502 cannotconnect
Another highly-upvoted answer suggests I need to "disable Windows 10 fast startup" -- I have not tried this yet, mainly because I'm not sure what the full repercussions are with that setting.
Is there something stupidly obvious that I'm overlooking here? Shouldn't I be able to run this on different ports? If not, why not? If I have to use 80:80, but System is already using that port, won't I have some further problems if I try to kill that pid?
PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> netstat -a -n -o | findstr :80 | findstr LISTENING
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:8003 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 1348
TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING 4688
TCP 127.0.0.1:8080 0.0.0.0:0 LISTENING 2016
TCP 127.0.0.1:8082 0.0.0.0:0 LISTENING 28536
TCP [::]:80 [::]:0 LISTENING 4
TCP [::]:8003 [::]:0 LISTENING 4
TCP [::]:8080 [::]:0 LISTENING 1348
TCP [::]:8081 [::]:0 LISTENING 4688
I made a small change in the Dockerfile changing EXPOSE 80 443 to EXPOSE 1337 443 and I'm now able to view my app by navigating to localhost:1337 in my browser. I think that will get me through the next steps in the training module, but still curious if I'm doing something wrong.
This seems to work regardless of the change in Dockerfile (I've removed and republished after changing Dockerfile).
PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 1337:80 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0
Try this
> net stop winnat
> docker start ...
> net start winnat
A part of the problem is that you're using the wrong mapping. The application uses the port 80, but you're mapping the ports 1337 to 1337.
The correct command should be:
PS C:\Users\david.zemens\Source\Repos\linux_tweet_app> docker container run --detach --publish 1337:80 --name linux_tweet_app $DOCKERID/linux_tweet_app:1.0
It may be because your IIS or some other server is already running on port 80.
Try stop the IIS and it should work.
Reference: https://forums.docker.com/t/error-starting-userland-proxy-listen-tcp-0-0-0-0-bind-an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissions/81299/7

Docker tutorial, localhost:4000 is inaccessible

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.

How do i run enketo-express on Ubuntu?

After setup of enketo express, When i run enketo-express using command "docker-compose up -d" on an ubuntu server, it shows an below error related to nginx
ERROR: for docker_nginx_1 Cannot start service nginx: b'driver failed programming external connectivity on endpoint docker_nginx_1 (7c414e255d50f42a0fa14d07c0b0d29125f666d77e55e5eb4437e43e3e4d9454): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use'
ERROR: for nginx Cannot start service nginx: b'driver failed programming external connectivity on endpoint docker_nginx_1 (7c414e255d50f42a0fa14d07c0b0d29125f666d77e55e5eb4437e43e3e4d9454): Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use'
By default 80 port is used by the apache service on ubuntu server. This means you need to change your port.
Just try to Bind port 8081 of your ubuntu with the port 80 of the container. For this use this command,
$ run docker run -d -p 8081:80 --name webserver nginx
This creates the link you need to access it at http://localhost:8081/
Note- Change port in "setup/docker/docker-compose.yml" file. eg: 80:80 to 8081:80
It's because something is already running on port 80 on the host machine.
View which process it is, get the PID -
$ lsof -i:80
$ netstat -tulnap | grep :80
Kill the process -
$ kill -9 $PID
Try now & you will be good -
$ docker-compose up -d

Can't connect to dockerized rabbit from clients

I installed and ran rabbitmq on docker from https://hub.docker.com/_/rabbitmq/:
docker ps
24551542aa20 repo/rabbitmq-example-server:latest "/docker-entrypoin..." 23 hours ago Up 2 hours 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp rabbitmq-example-server
I can login on the admin with http://localhost:15672/
From terminal I can use rabbitmqadmin succesfully for all the examples here http://www.rabbitmq.com/management-cli.html, adding -u admin -p nimda for authentication. I can publish and receive messages.
However, python and ruby clients cannot connect. TCP connection is refused or hangs.
I tried localhost,127.0.0.0.1 or my ip, nothing. The port 5672 is not even reachable with telnet and I see it declared in rabbitmq.config:
{ tcp_listeners, [ 5672 ] },
Just found the answer while writing the post :-)
nmap -p 5672 localhost
gives
PORT STATE SERVICE
5672/tcp closed amqp
So I stopped and removed the container and restarted again with
docker run -d -p 5672:5672 -p 15672:15672 --name rabbitmq rabbitmq
and now nmap gives
5672/tcp open amqp
and clients are connecting. I don't know why the rabbitmqadmin was to connect...

Docker port binding not working as expected

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.

Resources