How to make docker container use port other than 80 - docker

I try to deploy self hosted Bitwarden service: https://bitwarden.com/help/article/install-on-premise/
When I run install script I get the following error:
docker: Error response from daemon: driver failed programming external connectivity
on endpoint certbot
(393789b88f2a15db0ae5fb0d3fdce83e14bd4d4eb890ffff0f946dc607953815): Error starting
userland proxy: listen tcp4 0.0.0.0:80: bind: address already in use.
ERRO[0000] error waiting for container: context canceled
Which is expected because I already have NGINX on this VM with a couple of websites and port 80 is being used by the host.
I heard that is is possible to make docker container use another host port, instead of 80. That is container will have port 80, but it will be something else externally on the host. I tried to change the mapping in the install script like 5000:80 instead of 80:80 but I keep getting the same error.
Am I doing something wrong, or what I am trying to do is not possible?

You can add range to the command and it will use the first available port.
so -p 80-100:80.
TO get the port that your actually mapping to use docker ps and it will show you what port it's mapped to.

Related

Docker nginx ports are not available

I am trying to use nginx on docker for windows using
docker container run --publish 80:80 nginx
it is getting the error like below:
C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
can anyone give me the solution......
As you can see the error is clear Ports are not available: listen tcp 0.0.0.0:80: because the port is occupied. you have two option
Kill the process the occupied the port and then run the container
Publish different port then 80 for the Nginx contianer
container run --publish 81:80 nginx then localhost:81
Now open http://localhost:81 should work.

Port binding error when connecting to localhost Kafka broker from localhost Consumer in Docker container

I have a Zookeeper running on port 2181 (default) and a Kafka server listening on port 9090 on my local machine.
When I run kafka CLI locally, or consumer/producer apps locally, I have no problem connecting.
I then try to bundle a Kafka consumer into a Docker container, and run that Docker container locally, e.g.:
docker run -p 9092:9092 --rm <DOCKER_IMAGE>
This gives the error:
(Error starting userland proxy: Bind for 0.0.0.0:9090 failed: port is already allocated.)
This makes sense since Kafka Server is bound to 9092, as shown in nmap -p 9092 localhost:
PORT STATE SERVICE
9092/tcp open XmlIpcRegSvc
I'd have no problem mapping the Docker container to a different port via -p XXX:9090, but how do I get the local Kafka server to listen on that new port without binding to it?
So after some digging I found a few options. (Note: I'm on a mac so #2 may not be applicable to everyone).
Include --network=host in the docker run command (as seen here).
Don't change the docker run command at all, and instead connect to broker at host.docker.internal:9092 inside the container consumer/publisher code. As seen here.
I wasn't able to get #1 to work out for me (I'm sure it's user error). However #2 worked perfectly and just required a config change inside the container.

Connect a websocket client in a docker container to a websocket server in host

I have a websocket server running in my host, listening to port 8080.
In a docker container, I deployed a websocket client listening to the said server using this snippet:
connect_url="ws://0.0.0.0:80/"
and, exposing/mapping port 80 of the container to port 8080 of the host.
Dockerfile:
EXPOSE 80
When I ran the container:
docker run -p 8080:80 <name>
But I'm getting this error:
docker: Error response from daemon: driver failed programming external connectivity on endpoint : Error starting userland proxy: Bind for 0.0.0.0:8080 failed: port is already allocated.
Now I think this error is because the server in the host is already using port 8080, that's why it can't be mapped.
With these details given, I just wanted to know how can my websocket client inside the docker container connect to the websocket server in the host.
I think problem is port 80 inside your container already in use, not 8080 on your host machine. Try to use another port for connect socket inside your docker container instead 80 (for example 777 port). Then run docker run -p 8080:777 <name>
By the way, check your host machine port already in user or not:
sudo lsof -i tcp:8080
If not thing show up, that mean port 8080 not yet used. Incase already in use. Kill that process on port 8080:
sudo kill -9 your_PID_ID
Then try again

Error "Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE) in Docker

I tried to run an nginx server on my Mac with:
docker container run --publish 80:80 nginx
It is returning this error.
docker: Error response from daemon: driver failed programming external connectivity on endpoint hungry_shtern (88e68bd0a448ebe25a62c1c897d38a58e7cc581736ea55a0b764197d0416fce6): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).
How to fix this?
As other answers pointed, that port is already in use by some other service.
This service is the default apache installed on mac.
To confirm, try:
sudo lsof -i:80
And if you see the command httpd appearing there, the apache server is running, and using port 80.
You could also just try to access http://localhost:80 on your browser. If the apache server is running, you'll see something like "It works!".
To disable this service:
sudo apachectl -k stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
After the first command you will be able to bind that port with docker. After the second, you'll disable apachectl on startup.
Maybe port 80 is in use by another process, you need to kill that process or change bind port of docker container:
docker container run --publish 8080:80 nginx

Docker using mysql

Get following error, when trying to run MySQL in docker. Saying the ports is already in use, that would be for my local mysql database perhaps, how do I use docker and mysql
docker: Error response from daemon: driver failed programming external connectivity on endpoint stupefied_einstein (): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use.
Map you docker mysql container on another port when you start the container:
docker run -p 3307:3306 ...
The container port 3306 will be mapped on the host port 3307. (while your real mysql can use 3306)

Resources