Compose: ERROR: for db Cannot start service db: driver failed programming external connectivity on endpoint ltg_db_1

Created on 8 Nov 2016  Â·  52Comments  Â·  Source: docker/compose

when i do the following :

± docker-compose up
Starting ltg_db_1

ERROR: for db Cannot start service db: driver failed programming external connectivity on endpoint ltg_db_1 (ecc3bf3036508fade24ffa4d6bc3e5fee0180073c5351667c471922a10fad60f): Error starting userland proxy: Bind for 0.0.0.0:27017 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

image

image

image

± sudo docker inspect mongo
[
{
"Id": "sha256:135883d5d0b960b498e4c6c2009444b243b322d3fcb8fc4aa0cc741542dd6528",
"RepoTags": [
"mongo:latest"
],
"RepoDigests": [
"mongo@sha256:89ad0ed6321f48107356db1e11984e56614bdee64c3ad8a05484187f276ff705"
],
"Parent": "",
"Comment": "",
"Created": "2016-11-01T23:31:04.120003872Z",
"Container": "3e20e01de569b06a9cb43787870428254c585a56c2497835db2a616871db6f09",
"ContainerConfig": {
"Hostname": "397f80c505a4",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"27017/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"GPG_KEYS=DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \t42F3E95A2C4F08279C4960ADD68FA50FEA312927",
"MONGO_MAJOR=3.2",
"MONGO_VERSION=3.2.10",
"MONGO_PACKAGE=mongodb-org"
],
"Cmd": [
"/bin/sh",
"-c",
"#(nop) ",
"CMD [\"mongod\"]"
],
"ArgsEscaped": true,
"Image": "sha256:389bcb7270fe1b576cabbf8c087b3400c5cde2f3da89be0620a42d9a5ab977fe",
"Volumes": {
"/data/configdb": {},
"/data/db": {}
},
"WorkingDir": "",
"Entrypoint": [
"/entrypoint.sh"
],
"OnBuild": [],
"Labels": {}
},
"DockerVersion": "1.12.2",
"Author": "",
"Config": {
"Hostname": "397f80c505a4",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"27017/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"GPG_KEYS=DFFA3DCF326E302C4787673A01C4E7FAAAB2461C \t42F3E95A2C4F08279C4960ADD68FA50FEA312927",
"MONGO_MAJOR=3.2",
"MONGO_VERSION=3.2.10",
"MONGO_PACKAGE=mongodb-org"
],
"Cmd": [
"mongod"
],
"ArgsEscaped": true,
"Image": "sha256:389bcb7270fe1b576cabbf8c087b3400c5cde2f3da89be0620a42d9a5ab977fe",
"Volumes": {
"/data/configdb": {},
"/data/db": {}
},
"WorkingDir": "",
"Entrypoint": [
"/entrypoint.sh"
],
"OnBuild": [],
"Labels": {}
},
"Architecture": "amd64",
"Os": "linux",
"Size": 342458197,
"VirtualSize": 342458197,
"GraphDriver": {
"Name": "aufs",
"Data": null
},
"RootFS": {
"Type": "layers",
"Layers": [
"sha256:f96222d75c5563900bc4dd852179b720a0885de8f7a0619ba0ac76e92542bbc8",
"sha256:38e11f990b2e156924ac65dca751984df46e2ee08e910f3d5022b2cf719347ca",
"sha256:eafeecfceabdb3a4e1ca1102187836933e3ccc961739491a09e0363cf70b2f2e",
"sha256:70c36fdd993b7f4a91e6917b321c20511b12df2e0bf83942ff462a5f0a28a466",
"sha256:a03828149464bad8b594b6a08afb1f7203dc06da0b455cb12c50edd46ef668a5",
"sha256:b54cfe80c0ff24ce4144c7d4b902020c582a261f214349093b8f19bd9a5d8673",
"sha256:ec498496ec5310d8dec1e7d350da6d915b9f1cb27509892e6e6f18b7855303c0",
"sha256:5031b34889a540514acc2cf9182cda58fef892f359086cb7d05004da033a53c8",
"sha256:bde90abdc1c007d780ce1b34a692f9305b908cc7c0de3511d1d53f536e535570"
]
}

kinquestion

Most helpful comment

The following worked for me

# find container id running on the desired port from the following output
docker container ls
# stop the container running on the desired port
docker stop <container-id>

All 52 comments

Bind for 0.0.0.0:27017 failed: port is already allocated

You already have a container or application listening on the 27017 port on your machine, which prevents your service from allocating that port.

i stopped all the containers but still no solution.
then i tried to delete al the containers and still no solution.

Bump! Having the same issue

@AustinJuliusKim ive lost faith in Docker way of doing stuff.

Having the same issue

Having the same issue. I've tried everything from removing all the containers, images to restarting docker and resetting to factory defaults. Nothing works. When I try docker-compose up I'm getting the following error:
ERROR: for db Cannot start service db: driver failed programming external connectivity on endpoint djangocelerypsql_db_1 (47ff2801a196bcd458bc2bc44af66797552dc82c06b7122ab04b3c4d7cb25261): Error starting userland proxy: Bind for 0.0.0.0:5432 failed: port is already allocated ERROR: Encountered errors while bringing up the project.

and interestingly sudo netstat -p -nlp | grep 5432 returns nothing.

Similar issue.

ERROR: for db Cannot start service db: driver failed programming external connectivity on endpoint iotdemo_db_1 (7c482cab86489eb21c6884b1af49865a6b1760f0e53c20df1996824bc39af01e): Error starting userland proxy: listen tcp 0.0.0.0:8083: bind: address already in use

I was getting the same error but was able to successfully continue after:
service mongodb stop

I'm a little confused (and new to docker & compose, to be quite honest) but shouldn't a db service running on the host not have a conflict with a db service running within a container?

@aromasko Not if you're trying to expose it on the same port on the host.

when I docker network inspect MY_NETWORK, I found an old container which was allocated with that port had not been removed. I guess that's why the port could not be used for my new container.

Therefore, I removed the network with docker network rm MY_NETWORK and docker-compose up -d to recreate a network and restart all containers. Finally, it got fine.

Does anyone have a solution for this!?

Exact same issue, with redis.
All other port mappings seem to work well, using db or redis fails on mac os.

I was getting this issue on Docker for Windows, both ports 5432 and 80. I had a local instance of Postgres blocking 5432 and IIS was blocking port 80. Stopping both of those services fixed the issue for me.

service mongodb stop worked for me

service mongodb stop worked for me - we had a mongodb running on the server which conflicted with the one running in the docker....

Did someone solve that problem?

Yea I'm wondering as well, I can't open the darn ting

I just used port mapping and problem has been solved. For example set mongo port 27018:27017 in docker-compose file.

I actually was using an older git version. Updated and it worked just fine!

The following worked for me

# find container id running on the desired port from the following output
docker container ls
# stop the container running on the desired port
docker stop <container-id>

Similar to what is suggested here in the linked article, turning off MySQL in System Preferences is what worked for me. https://medium.com/code-wave/error-starting-userland-proxy-bind-for-0-0-0-0-3306-failed-port-is-already-allocated-docker-f2e430f68346

@samhstn You save my day

i used service mongodb stop and it worked for me perfectly :)

I was also facing the same issue. here are the steps I did to resolve the problem:
1) List all container : docker ps -a
2) Stop all if not stopped : docker stop [containerid]
3) Remove containers : docker rm [containerid]
4) Now try to launch services with docker compose: docker-compose up
Hope this will help :)

@ShreyasDeshpande, after the 4th step, i get the same error, but with a different container id

@aayushagrawal135 can you try to stop that container and remove it and again try with launching the service.
docker ps -a
docker stop [container ids]
docker rm [container ids]
docker-compose up

I tried,
docker-compose down
docker-compose up

It worked. What happened when docker-compose down was executed?

On Mon 28 Jan, 2019, 13:46 Shreyas Deshpande <[email protected]
wrote:

@aayushagrawal135 https://github.com/aayushagrawal135 can you try to
stop that container and remove it and again try with launching the service.
docker ps -a
docker stop [container ids]
docker rm [container ids]
docker-compose up

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/docker/compose/issues/4126#issuecomment-458033946,
or mute the thread
https://github.com/notifications/unsubscribe-auth/APZhuIxPbpn2WUPW27H7Z0db2eYSoDpUks5vHrHLgaJpZM4KsAI2
.

Just restart docker. It will fix the issue.

What happened to me was that i was specifying unnecessarily the ports trying to fix another error

  db:
    image: postgres:11
    volumes:
      - postgres_data:/var/lib/postgresql/data
    ports:
      - 5432:5432

So i just removed the ports and all went well

lsof -i | grep '3306' doesn't get me anything and a complete stop, reload, up -d of docker-compose doesn't fix it.

Somehow even though I couldn't find it with lsof -i | grep '3306' running sudo kill $(sudo lsof -t -i:8080) did fix the issue for me

Just restart docker. It will fix the issue.

Worked...like a charm.

If nothing works, just restart Docker and do

docker-compose up --build

If nothing works, just restart Docker and do

docker-compose up --build

That isn't going to help people much if it's an external program causing the issue

Having the same issue.
I have tried:

  • docker rm
  • docker rmi
  • docker stop
  • docker start

But still not working.
image

@sanymochi try this sudo kill $(sudo lsof -t -i:8761)

This works as charm. replace the port number with one that raises the issue.

The following worked for me

# find container id running on the desired port from the following output
docker container ls
# stop the container running on the desired port
docker stop <container-id>

For people still looking out for a solution, this works. And kinda gives you an insight on the issue as well.

To fix this find the process pid with:

lsof -i :3000

Then kill the process with:

kill -9 pid

With Docker on Windows 10, I listen before used ports with:
netstat -ano | grep 3306 (using cmder, or some bash terminal)

I had this result:
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 18076
TCP [::]:3306 [::]:0 LISTENING 18076

after that, opened Windows Command Shell with 'cmd' and killed that process with:

taskkill /pid 18076 /f

After that, I restarted Docker and re-up the docker-compose app.

Thank you @michelefalconi,
it`s wirk for me in windows 10,

  1. Open PowerShell like Administrator
    2.netstat -ano | Select-String 3306
  2. taskkill /pid 6108 /f
  3. Restart my docker
  4. docker-compose up

it's a boring work, always happen but it's work fine

I just used port mapping and problem has been solved. For example set mongo port 27018:27017 in docker-compose file.

This was my remedy.

I just used port mapping and problem has been solved. For example set mongo port 27018:27017 in docker-compose file.

This works fine :) :)

I run this command to see port application used
ss -tulpn

and after kill application like Postgres which used port ...

I was getting the same error but was able to successfully continue after:
service mongodb stop

I'm a little confused (and new to docker & compose, to be quite honest) but shouldn't a db service running on the host not have a conflict with a db service running within a container?

It depends on how the port was mapped.

Here's a solution. Remove untagged images.
Save the below code as docker_cleaner.sh
sudo ./docker_cleaner.sh

Problem will be solved.

#!/usr/bin/env bash
# options:
# remove stopped containers and untagged images
#   $ dkcleanup
# remove all stopped|running containers and untagged images
#   $ dkcleanup --reset
# remove containers|images|tags matching {repository|image|repository\image|tag|image:tag}
# pattern and untagged images
#   $ dkcleanup --purge {image}
# everything
#   $ dkcleanup --nuclear

if [ "$1" == "--reset" ]; then
    # Remove all containers regardless of state
    docker rm -vf $(docker ps -a -q) 2>/dev/null || echo "No more containers to remove."
elif [ "$1" == "--purge" ]; then
    # Attempt to remove running containers that are using the images we're trying to purge first.
    (docker rm -vf $(docker ps -a | grep "$2/\|/$2 \| $2 \|:$2\|$2-\|$2:\|$2_" | awk '{print $1}') 2>/dev/null || echo "No containers using the \"$2\" image, continuing purge.") &&\
    # Remove all images matching arg given after "--purge"
    docker rmi $(docker images | grep "$2/\|/$2 \| $2 \|$2 \|$2-\|$2_" | awk '{print $3}') 2>/dev/null || echo "No images matching \"$2\" to purge."
else
    # This alternate only removes "stopped" containers
    docker rm -vf $(docker ps -a | grep "Exited" | awk '{print $1}') 2>/dev/null || echo "No stopped containers to remove."
fi

if [ "$1" == "--nuclear" ]; then
    docker rm -vf $(docker ps -a -q) 2>/dev/null || echo "No more containers to remove."
    docker rmi $(docker images -q) 2>/dev/null || echo "No more images to remove."
else
    # Always remove untagged images
    docker rmi $(docker images | grep "<none>" | awk '{print $3}') 2>/dev/null || echo "No untagged images to delete."
fi

exit 0

Tendo o mesmo problema. Eu tentei de tudo, desde remover todos os contêineres, imagens até reiniciar a janela de encaixe e redefinir os padrões de fábrica. Nada funciona. Quando tento docker-compose up, estou recebendo o seguinte erro:
ERROR: for db Cannot start service db: driver failed programming external connectivity on endpoint djangocelerypsql_db_1 (47ff2801a196bcd458bc2bc44af66797552dc82c06b7122ab04b3c4d7cb25261): Error starting userland proxy: Bind for 0.0.0.0:5432 failed: port is already allocated ERROR: Encountered errors while bringing up the project.

e curiosamente sudo netstat -p -nlp | grep 5432nada retorna.

Isso Aqui funcionou para mim: service postgresql stop

started happening after the updating the docker for windows 10 to version - 2.3.0.4 - 46911. Restarting the Docker is not working.
sudo lsof -t -i:5432 returns nothing. I checked all the above commands and nothing is working.

Edit: -
What did help for me was restarting my system.

Hey everyone.
I had the same issue, however solved it by making sure no ports were clashing.
Hope this works for you! :+1:

sudo lsof -i:3306
kill -9

bad time for this, :(

I just used port mapping and problem has been solved. For example set mongo port 27018:27017 in docker-compose file.

This worked perfectly !!

Was this page helpful?
0 / 5 - 0 ratings