Docker-Compose Postgres 5432 Bind: Address already in use error - node.js

Alright so I've been searching for 3-4 days now and I can't seem to find a solution to my error. I have found similar errors, and some that seemed to be describing my exact issue but none of the solutions worked.
I'm trying to get a simply postgres, express, node app up and running. I want to be able to run docker-compose up -d and have it build all of the images, volumes, etc. Then I will run a bash script that will seed my postgres db with data. However, I keep getting an error with the ports I'm using. I've removed all of my images, containers, and even reinstalled docker but I can't figure it out. I removed everything from my docker-compose except for the postgres and it still doesn't work.
version: '3'
services:
postgres:
image: postgres:10.0
volumes:
- /var/lib/postgresql/data
ports:
- '5432:5432'
Then on my host machine I simply plan on running the following bash script.
#!/bin/bash
host="postgres.dev"
adminUser="postgres"
psql -h $host -U $adminUser -c "select 1 from pg_database where datname = 'table_name';" | grep -q 1 || psql -h $host -U $adminUser -f ./"$(dirname $0)"/init-local-db.sql
I know that this approach should work since I'm patterning it after a work project...which works for them. But here's the error I get:
ERROR: for pg-db Cannot start service postgres: driver failed programming external connectivity on endpoint pg-db (b3e5697cd563264250479682ec83d4a232d0d4bd679a787ad2089e944dda9e2f): Error starting userland proxy: listen tcp 0.0.0Creating test-api ... done
ERROR: for postgres Cannot start service postgres: driver failed programming external connectivity on endpoint pg-db (b3e5697cd563264250479682ec83d4a232d0d4bd679a787ad2089e944dda9e2f): Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use
ERROR: Encountered errors while bringing up the project.
I know some people say to simply change the port number so '5433:5432' but my problem with this is that when you install postgres by default its port is 5432, and I know it's not necessary to change it(because the work project doesn't). Any thoughts?
Update (next morning):
Okay I still have no idea why the error popped up in the first place, as I used lsof -i tcp:5432 (along with netstat) and nothing came up as using that port. I put my computer in suspend mode and went to bed. In the morning I woke up, changed my postgres version to 9.6 to see if that was it, and everything worked. I then switched it back to postgres 10.0 and again everything worked. Hopefully it won't pop back up again, but I have no idea why it popped up in the first place.

There is only one reason you may be getting this error. You have PostgreSQL installed on your local machine and it's running, occupying the port 5432.
You have the following options:
Disable (and remove from startup) PostgreSQL on your local machine. - Your Docker Compose will run.
sudo service postgresql stop
sudo update-rc.d postgresql disable
Use a different port in docker-compose. There is nothing wrong with applying '5433:5432'. Other services of your docker-compose will connect to postgres by 5432 port. From your local machine you'll be able you address postgres by localhost:5433.

Related

What can I do when bind: adress already in use?

When I want to run my network with hyperledger fabric v. 2 and couchdb I get following error for all couchdb and ppeers:
WARNING: Host is already in use by another container
ERROR: for ca_peerOrg1 Cannot start service ca0: driver failed programming external connectivity on endpoint ca_peerOrg1 (e1ebe2f0cbdbddf0a1873a3db798e21ecd9aa5bac1944eb522bddaedabc87eba): Error starting userland proxy: listen tcp 0.0.0.0:7054: bind: address already in use
Creating ca_peerOrg2 ... error
What I have done so far, but wasn't helping:
docker rm -f $(docker ps -a -q)
Then I wanted to stop docker compose, by follwoing command:
docker-compose stop
But I got some errors, and actually I installed docker compose before.
Then I removed the images and installed them again with the commands:
I am always working in the same project. Just starting it sometimes again, to solve some errors.
I do not understand, how I can all bring down and up again.
For starting my network I use following command:
sudo ./start_Network.sh
If I want to use sudo ./start_Network.sh down is not working.
What can I do to solve my errors?

Docker: Error starting userland proxy: Bind for 0.0.0.0:50000: unexpected error Permission denied on Azure VM

I'm new to Docker so please be kind but I am testing it out on a Windows 10 image on Azure (I know I could run it directly but I wanted to try it in a VM first).
I have a fresh Windows 10 image that I have installed Docker for Windows 2.0.0 on.
Note: I did not tick the option to use Windows containers instead of linux containers.
Once it installed (and rebooted) I was prompted to install Hyper-V and Containers features (causing restarts).
Once it was all installed I open an Administrative PowerShell window to download Jenkins:
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
This gave me the error:
C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: driver failed programming external connectivity on endpoint goofy_lederberg (deaba2deeea0486c92ba8a1a32740295f03859b1b5829d39e39eff0b24613ebf): Error starting userland proxy: Bind for 0.0.0.0:50000: unexpected error Permission denied.
I thought this was strange as 50000 wasn't a port that I expected to be in use, changing this to different ports (50001) produced the same error.
Running:
netstat -a -n -o
Showed that the port was not in use.
If I remove -p 50000:50000 from the command it can bind and start Jenkins but I assume it needs this port mapping to work correctly.
Previous posts have suggested stopping the World Wide Web Publishing service but that isn't installed.
There are no other running Docker containers.
I assume the port is in use or something is stopping the port mapping.
Assuming a user has permission to create a port binding from their terminal are there any other techniques beside netstat to determine if something is bound to a port - either something internal to docker's own checking process or something at the host OS level?
Rather embarrassingly this worked this morning with no changes other than the VM was shutdown over the weekend.
Maybe all it needed was a reboot?

Error connecting to docker container

I installed a service on a remote Linux computer using docker. I used the following commands
git clone https://github.com/OpenVidu/openvidu-tutorials.git
npm install -g http-server
http-server openvidu-tutorials/openvidu-getaroom/web
docker run -p 4443:4443 --rm -e openvidu.secret=MY_SECRET -e openvidu.publicurl=https://187.84.228.66:4443 openvidu/openvidu-server-kms
But when I try do connect at the first time, I received the follow error menssage:
"ERR_EMPTY_RESPONSE", and sometime "ERR_CONNECTION_CLOSED"
I used the following diagnostic command in Linux computer “docker ps” and received the following response:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21b0620266cd openvidu/openvidu-server-kms:latest "/usr/bin/supervisor 5 days ago >Up 5 days 8443/tcp, 8888/tcp, 0.0.0.0:4443->4443/tcp, 9091/tcp sick_ritchie
What is wrong? How can I solve this?
I'm not sure sure what causes this, but when I had the same problem (with different http server) I changed listening on particular ip address (which was 127.0.0.1 in my case) to listening on all interfaces - 0.0.0.0.
I mean http server configuration, not Docker configuration.

Can't run Rocket.Chat server on Ubuntu without Docker

I've been following this tutorial to install Rocket.Chat on Ubuntu:
https://github.com/RocketChat/Rocket.Chat/wiki/Deploy-Rocket.Chat-without-docker
Everything looks good until I try to run the server with node main.js:
Error: failed to connect to [localhost:27017]
at Object.Future.wait (/home/gregoire/Rocket.Chat/programs/server/node_modules/fibers/future.js:398:15)
at new MongoConnection (packages/mongo/mongo_driver.js:213:1)
localhost could also be 127.0.0.1 or my IP address, it doesn't change anything. Sounds like an error coming from MongoDB.
So I tried to run with sudo and the error I'm getting is different:
Error: MONGO_URL must be set in environment
I follow the tutorial, this variable has been set using export:
export ROOT_URL=http://localhost/
export MONGO_URL=mongodb://localhost:27017/rocketchat
export PORT=80
EDIT:
I needed to start mongod to then run the main.js. But I also got an error:
mongodb failed to connect to 127.0.0.1
I made some research and found that I had a missing folder. I used this command to create it and then started mongod:
mkdir -p /data/db
It worked after that, but it's not implied in the tutorial. I'm currently repeating the setup on a server and I'm having the same problem: /data/db is missing.
Disclaimer: I work for Rocket.Chat.
Are you sure mongodb is running? Can you type mongo and see if you can get into a mongoDB shell? If it's running, can you please confirm it's running on port 27017?
You can also go to https://demo.rocket.chat and join #support channel or #dev, where you'll find quite a few developers willing to help you out.

Couchdb cartridge not responding in docker image

I successfully deployed a couchdb cartridge to wso2stratos and member get activated successfully. For the implementation of the dockerfile i used this git code. which include the below line that i have no idea why it is there! Can someone explain the below code?
RUN printf "[httpd]\nport = 8101\nbind_address = 0.0.0.0" > /usr/local/etc/couchdb/local.d/docker.ini
EXPOSE 8101
CMD ["/usr/local/bin/couchdb"]
I tried pointing http://127.0.0.1:5984/_utils/spec/run.html url and its working perfectly.
I just SSH to the docker container and start the couchdb,
root#instance-00000001:/usr/local/etc/couchdb/local.d# couchdb couchdb
Apache CouchDB 1.6.1 (LogLevel=info) is starting.
Apache CouchDB has started. Time to relax.
[info] [<0.32.0>] Apache CouchDB has started on http://0.0.0.0:8101/
Then I try to pointing the browser to http://0.0.0.0:8101/ and http://127.0.0.1:5984/_utils/index.html both of them not working.
Can someone tell me why i can't view my databases and create database window?
For your first question about what those lines do:
# Set port and address for couchdb to bind too.
# Remember these are addresses inside the container
# and not necessarily publicly available.
# See http://docs.couchdb.org/en/latest/config/http.html
RUN printf "[httpd]\nport = 8101\nbind_address = 0.0.0.0" >
/usr/local/etc/couchdb/local.d/docker.ini
# Tell docker that this port needs to be exposed.
# You still need to run -P when running container
EXPOSE 8101
# This is the command which is run automatically when container is run
CMD ["/usr/local/bin/couchdb"]
As for why you cannot access it, What does your docker run command look like, did you expose the port? i.e.
docker run -p 8101:8101 ....
Are you by any chance testing on OSX? If so try http://192.168.59.103:8101/ On OSX docker would be inside a virtual box VM as docker cannot run natively on OSX. The IP of the virtual machine can be looked up using boot2docker ip and is normally 192.168.59.103.

Resources