Port is already allocated docker как исправить

I am using docker for the first time and I was trying to implement this - https://docs.docker.com/get-started/part2/#tag-the-image At one stage I was trying to connect with localhost by this comman...

I am using docker for the first time and I was trying to implement this —
https://docs.docker.com/get-started/part2/#tag-the-image

At one stage I was trying to connect with localhost by this command —

$ curl http://localhost:4000

which showed this error-

curl: (7) Failed to connect to localhost port 4000: Connection refused

However, I have solved this by following code —

$ docker-machine ip default
$ curl http://192.168.99.100:4000

After that everything was going fine, but in the last part, I was trying to run the app by using following line according to the tutorial…

$ docker run -p 4000:80 anibar/get-started:part1

But, I got this error

C:Program FilesDocker Toolboxdocker.exe: Error response from daemon: driver failed programming external connectivity on endpoint goofy_bohr (63f5691ef18ad6d6389ef52c56198389c7a627e5fa4a79133d6bbf13953a7c98): Bind for 0.0.0.0:4000 failed: port is already allocated.

John Kugelman's user avatar

John Kugelman

343k67 gold badges518 silver badges566 bronze badges

asked Sep 12, 2017 at 12:37

Anik Barua's user avatar

You need to make sure that the previous container you launched is killed, before launching a new one that uses the same port.

docker container ls
docker rm -f <container-name>

answered Sep 12, 2017 at 13:17

yamenk's user avatar

yamenkyamenk

44.2k10 gold badges89 silver badges86 bronze badges

3

Paying tribute to IgorBeaz, you need to stop running the current container. For that you are going to know current CONTAINER ID:

$ docker container ls

You get something like:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                  NAMES
12a32e8928ef        friendlyhello       "python app.py"     51 seconds ago      Up 50 seconds       0.0.0.0:4000->80/tcp   romantic_tesla   

Then you stop the container by:

$ docker stop 12a32e8928ef

Finally you try to do what you wanted to do, for example:

$ docker run -p 4000:80 friendlyhello

answered Oct 6, 2017 at 10:17

1

I tried all the above answers, none of them worked, in my case even docker container ls doesn’t show any container running. It looks like the problem is due to the fact that the docker proxy is still using ports although there are no containers running. In my case I was using ubuntu. Here’s what I tried and got the problem solved, just run the following two commands:

sudo service docker stop
sudo rm -f /var/lib/docker/network/files/local-kv.db

answered Jul 12, 2020 at 5:56

Fahima Mokhtari's user avatar

Fahima MokhtariFahima Mokhtari

1,4911 gold badge15 silver badges29 bronze badges

6

I solved it this way:

First, I stopped all running containers:

docker-compose down

Then I executed a lsof command to find the process using the port (for me it was port 9000)

sudo lsof -i -P -n | grep 9000

Finally, I «killed» the process (in my case, it was a VSCode extension):

kill -9 <process id>

answered Jun 24, 2019 at 1:48

Alexandre Lara's user avatar

Alexandre LaraAlexandre Lara

2,3941 gold badge28 silver badges35 bronze badges

1

The quick fix is ​​a just restart docker:

  1. sudo service docker stop
  2. sudo service docker start

answered Jan 4, 2021 at 8:03

DevTomek's user avatar

DevTomekDevTomek

4014 silver badges6 bronze badges

Above two answers are correct but didn’t work for me.

  1. I kept on seeing blank like below for docker container lsenter image description here
  2. then I tried, docker container ls -a and after that it showed all the process previously exited and running.
  3. Then docker stop <container id> or docker container stop <container id> didn’t work
  4. then I tried docker rm -f <container id> and it worked.
  5. Now at this I tried docker container ls -a and this process wasn’t present.

answered Jan 29, 2019 at 16:15

paul's user avatar

paulpaul

4,20516 gold badges65 silver badges138 bronze badges

2

When I used nginx docker image, I also got this error:

docker: Error response from daemon: driver failed programming external connectivity on endpoint recursing_knuth (9186f7d7f523732b99d3510029cde9679f3f3fe7b7eb5f612d54c4aacea58220): Bind for 0.0.0.0:8080 failed: port is already allocated.

And I solved it using following commands:

$ docker container ls
$ docker stop [CONTAINER ID]

Then, running this docker container(like this) again is ok:

$ docker run -v $PWD/vueDemo:/usr/share/nginx/html -p 8080:80 -d nginx:alpine

You just need to stop the previous docker container.

answered Jul 13, 2021 at 7:36

Wonz's user avatar

WonzWonz

2114 silver badges6 bronze badges

I have had same problem with docker-compose, to fix it:

  1. Killed docker-proxy processe
  2. Restart docker
  3. Start docker-compose again

alper's user avatar

alper

2,6487 gold badges48 silver badges91 bronze badges

answered Jun 21, 2019 at 9:12

KIA CEED's user avatar

KIA CEEDKIA CEED

2754 silver badges11 bronze badges

on linux ‘sudo systemctl restart docker’ solved the issue for me

answered Apr 27, 2022 at 7:20

Yassine Chilali's user avatar

docker ps will reveal the list of containers running on docker. Find the one running on your needed port and note down its PID.

Stop and remove that container using following commands:

docker stop PID
docker rm PID

Now run docker-compose up and your services should run as you have freed the needed port.

John Kugelman's user avatar

John Kugelman

343k67 gold badges518 silver badges566 bronze badges

answered Aug 29, 2019 at 7:44

Akshay Vijay Jain's user avatar

For anyone having this problem with docker-compose.
When you have more than one project (i.e. in different folders) with similar services you need to run docker-compose stop in each of your other projects.

answered Feb 13, 2019 at 19:36

everyman's user avatar

everymaneveryman

3,3671 gold badge33 silver badges33 bronze badges

0

If you are using Docker-Desktop, you can quit Docker Desktop and then restart it. It solved the problem for me.

answered Mar 10, 2021 at 14:00

J. Doe's user avatar

J. DoeJ. Doe

12.2k9 gold badges57 silver badges103 bronze badges

In my case, there was no process to kill.

Updating docker fixed the problem.

answered Jan 10, 2021 at 21:43

Matt's user avatar

MattMatt

4,0834 gold badges38 silver badges56 bronze badges

It might be a conflict with the same port specified in docker-compose.yml and docker-compose.override.yml or the same port specified explicitly and using an environment variable.

I had a docker-compose.yml with ports on a container specified using environment variables, and a docker-compose.override.yml with one of the same ports specified explicitly. Apparently docker tried to open both on the same container. docker container ls -a listed neither because the container could not start and list the ports.

answered Jan 3, 2021 at 9:18

Charlie's user avatar

CharlieCharlie

8,3712 gold badges53 silver badges52 bronze badges

1

For me the containers where not showing up running, so NOTHING was using port 9010 (in my case) BUT Docker still complained.

I did not want to reset my Docker (for Windows) so what I did to resolve it was simply:

  1. Remove the network (I knew that before a container was using this network with the port in question (9010) docker network ls docker network rm blabla (or id)
  2. I actually used a new network rather than the old (buggy) one but shouldn’t be needed
  3. Restart Docker

That was the only way it worked for me. I can’t explain it but somehow the «old» network was still bound to that port (9010) and Docker kept on «blocking» it (whinching about it)

answered May 18, 2021 at 6:43

Ray's user avatar

RayRay

1381 gold badge2 silver badges13 bronze badges

1

FOR WINDOWS;
I killed every process that docker use and restarted the docker service on services. My containers are working now.
It is about ports that is still in use by Docker even though you are not using on that moment.

answered Aug 18, 2022 at 7:31

Onur Bolaca's user avatar

1

On Linux, you can run sudo netstat -tulpn to see what is currently listening on that port. You can then choose to configure either that process or your Docker container to bind to a different port to avoid the conflict.

Colin O'Dell's user avatar

Colin O’Dell

8,1218 gold badges39 silver badges74 bronze badges

answered Jul 2, 2021 at 13:06

Rodut Naitsirc's user avatar

Stopping the container didn’t work for me either. I changed the port in docker-compose.yml.

answered Feb 11, 2019 at 1:14

Morgan's user avatar

MorganMorgan

1,2601 gold badge15 silver badges15 bronze badges

For me, the problem was mapping the same port twice.

Due to a parametric docker run, it ended up being something like

docker run -p 4000:80 -p 4000:80 anibar/get-started:part1

notice double mapping on port 4000.

The log is not informative enough in this case, as it doesn’t state I was the cause of the double mapping, and that the port is no longer bound after the docker run command returns with a failure.

answered Jan 20, 2022 at 17:50

Gulzar's user avatar

GulzarGulzar

21k22 gold badges104 silver badges173 bronze badges

1

Had the same problem. Went to Docker for Mac Dashboard and clicked restart. Problem solved.

answered Mar 15, 2022 at 11:32

undefined's user avatar

undefinedundefined

6508 silver badges18 bronze badges

0

Don’t forget the easiest fix of all….

Restart your computer.

I have tried most of the above and still couldn’t fix it. Then just restart my Mac and then it’s all back to normal.

E_net4's user avatar

E_net4

26.3k13 gold badges93 silver badges130 bronze badges

answered Aug 11, 2021 at 4:24

Ken Ratanachai S.'s user avatar

2

For anyone still looking for a solution, just make sure you have binded your port the right way round in your docker-compose.yml

It goes:
- <EXTERNAL SERVER PORT>:<INTERNAL CONTAINER PORT>

answered Mar 2, 2022 at 21:02

gellowg's user avatar

my case was dump XD I was exposing port 80 twice :D

        ports:
            - '${APP_PORT:-80}:80'
            - '${APP_PORT:-8080}:8080'

APP_PORT is defined, thus 80 was exposed twice.

answered Sep 28, 2022 at 14:05

shamaseen's user avatar

shamaseenshamaseen

2,0192 gold badges19 silver badges33 bronze badges

I tried almost all solutions and found out the probable/possible reason/solution. So, If you are using traefik or any other networking server, they internally facilitate proxy for load balacing. That, most use the blueprint as it, works pretty fine. It then passes the load control entirely to nginx or similiar proxy servers. So, stopping, killing(networking server) or pruning might not help.

Solution for traefik with nginx,

sudo /etc/init.d/nginx stop
# or
sudo service nginx stop
# or
sudo systemctl stop nginx

Credits

answered Nov 10, 2022 at 7:39

Henshal B's user avatar

Henshal BHenshal B

1,3009 silver badges11 bronze badges

How to stop docker processes

Making Docker Stop Itself <- Safe and Fast

this is the best way to stop containers and all unstoppable processes: making docker do the job.


go to docker settings > resources. change any of the resource and click apply and restart.


docker will stop itself and its every process — even the most stubborn ones that might not be killed by other commonly used commands such as kill or more wild commands like rm suggested by others.

i ran into a similar problem before and all the good — proper — tips from my colleagues somehow did not work out. i share this safe trick whenever someone in my team asks me about this.

Error response from daemon: driver failed programming external connectivity on endpoint foobar
Bind for 0.0.0.0:8000 failed: port is already allocated

hope this helps!

answered Dec 8, 2022 at 1:32

NamsanBaby's user avatar

1

simply restart your computer, so the docker service gets restarted

answered Apr 16, 2022 at 7:25

user4894254's user avatar

Docker error port is already allocated occurs when there is already a container is running on the same port on which we want to run a new process.

Here at Bobcares, we have seen several causes for this error while troubleshooting Docker issues as part of our Server Management Services for web hosts and online service providers.

Today we’ll take a look at the cause for this error and how to fix it.

Why does the docker error port is already allocated occur?

Before we get into the resolution part of the error, let us now see what causes this error to occur.

This error normally occurs when you try to run any container on a port that is already being used by some other container. This happens when we forget to kill the previously launched container.

For instance, the error appears as below.

docker error port is already allocated

This error means that there is already something running on port 4000. So it is not allowing any other container to run on the same port.

How we fix docker error port is already allocated

Recently, one of our customers approached us with this docker error which was showing the port to be already allocated. Let us now see how our Support Engineers resolve this error to our customers.

Initially, we find what container is running. For that, we ran the below command to know the currently running container’s ID:

$ docker container ls

Then we ran the below command to stop the already running container (Here, we replaced container_id with the actual container ID).

$ docker stop container_id

After that we asked the customer to resume the task that he wanted to do. Finally, it worked well.

[Need any further assistance in fixing Docker errors? – We’re available 24*7]

Conclusion

In short, this Docker error occurs when the previously running container is still active. Today, we saw how our Support Engineers resolve this error to our customers.

Are you using Docker based apps?

There are proven ways to get even more out of your Docker containers! Let us help you.

Spend your time in growing business and we will take care of Docker Infrastructure for you.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Docker Support

Spend time on your business, not on your servers.

Managing a server is time consuming. Whether you are an expert or a newbie, that is time you could use to focus on your product or service. Leave your server management to us, and use that time to focus on the growth and success of your business.

TALK TO US
Or click here to learn more.

@shin-

@budnik

Hi @shin- ,

I just did a hard reset on my machine and I get:

$ docker-compose up
_collections.so could not be extracted!

After that I have the same issue as posted by @PatrickConnors :
selection_055

Any ideas?

@shin-

@budnik Try running docker-compose down to clean up containers and networks, then up again and see if that fixes things.

gjingdx, sergey884, realnsleo, rohitPhutane1993, bvego, RobertTownley, JavierRodriguezRED, LeVuMinhHuy, dennisqi, Garlandal, and 141 more reacted with thumbs up emoji
stevengrimaldo, k4fer74, AntonZelenin, brianschardt, lukeleppan, anjneeksharma, robturtle, julianwagle, bluenote10, nurkeevich, and 44 more reacted with thumbs down emoji
JackOfSpade, VachetVirginie, dtopaloglou, and WAfonsoMarques reacted with laugh emoji
KyllianHmd, Evshved, shubhamg931, Helg18, alialsaihaty, sunil-lulla, anasbalkhadir, JackOfSpade, 0xywzx, nelsonic, and 7 more reacted with hooray emoji
Anti-user, briandiaz, anand1c, luscas, edoardo90, mahdithejedi, k4fer74, salalaiko1557, nenravitsa, jollyjerr, and 14 more reacted with confused emoji
anasbalkhadir, nelsonic, WAfonsoMarques, yuleidyvdres, Chaman-Raghav-Inno, i1idan, carlosaldaravi, and rshtishi-dexi reacted with heart emoji
tlatldms, lucasfonmiranda, IvanKushchenko, AnneNamuli, uqattan, fredpolicarpo, anand1c, KyllianHmd, edoardo90, Neverrock, and 10 more reacted with rocket emoji
anasbalkhadir and Demianeen reacted with eyes emoji

@lorenzo-pasa

I ran into the same issue today (with a postgres container), and despite having tried docker-compose down and then up again, the problem still persists.

Both docker-compose ps and docker ps show me an empty output.


I may have found a solution, though:

this is how my postgres service is defined

version: '2.1'

services:

  postgres:
    image: postgres:9.5.4
    env_file:
      - docker-compose.env
    ports:
      - 5432:5432

and in my case the fix was simply to disable the port binding, that is changing the last part as:

Not sure if this is the right solution, nor if it can be generally applied to all use cases.


Might it be an issue with docker-compose itself ?
For reference:

$ docker-compose --version
docker-compose version 1.12.0, build b31ff33
hackermanmx, randytorres, diegobladisk8, weblancaster, diegofreitas, zharikovpro, alexleone, rosshadden, BobbaTea, timendez, and 325 more reacted with thumbs up emoji
otheus, omrishalev22, mellena1, dablmo1819daw2, larikov, maxjing, buseodaci, raphaelbruno, riginoommen, rui-ren, and 5 more reacted with thumbs down emoji
BobbaTea, bcb, makdah1, aswanevelder, austinyearlykim, antoniotmll, milandashara, SarahKhaled, dondrzzy, marcosleonel, and 22 more reacted with laugh emoji
Martinnord, BleedingEffigy, BobbaTea, bledari, timendez, aswanevelder, austinyearlykim, mirr254, nyawqabob, milandashara, and 58 more reacted with hooray emoji
buseodaci, planet17, rui-ren, Musyimi97, leila-koho, and VolodymyrOstapiuk reacted with confused emoji
spmsupun, aswanevelder, ralphcorleone, austinyearlykim, fclesio, nyawqabob, milandashara, Devether15, steida, serchavalos, and 66 more reacted with heart emoji
leila-koho, slackermorris, DimasikS12, daveed, scimerman, and i1idan reacted with rocket emoji

@hackermanmx

lorenzo-pasa, BobbaTea, vmakre, fclesio, samueldervis, marcosleonel, vanderheijden86, alejandraklachquin, matthiasprieth, ptsilva, and 26 more reacted with hooray emoji

@weblancaster

I was having the same issue after updating my docker-compose to 3.3 version.
@lorenzo-pasa solution work locally for me (still need to try in prod)

Below is part of my docker-compose for reference:

nginx:
    image: nginx:1.12.2-alpine
    volumes:
      - .:/usr/share/nginx/app
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - "80"
    depends_on:
      - web

@realmhamdy

I had this and also stuff like Cannot start service mysql: network 4b8e7a23e3724fd351e428be30cdf7a9294d142ac23959ca9092278fc81e96c1 not found. I resolved them by using --build --force-recreate flags for the up command.

@Rub21

This 👇 works for me!!

docker-compose down
docker rm -fv $(docker ps -aq)
sudo lsof -i -P -n | grep 5432
  • For Mac
  • Linux
Sobranier, rhysawilliams2010, gjingdx, dxvargas, corpulent, laurenkosub, timendez, Meshari93, mikestaub, HillLiu, and 300 more reacted with thumbs up emoji
stevengrimaldo, Yasmine-Marzouk, debajyoti-thetaonelab, saikat056, fadhilinsemwa, lemystic, and Akilesh124 reacted with thumbs down emoji
achraf-jeday, logbasex, riskgod, noisytoken, margiechubin, namdaoduy, sonlexqt, akhbar, ali-master, fandy, and 7 more reacted with laugh emoji
R-iskey, milanij, ProgramCpp, allanshajimanamel-zz, la0rg, G-nsyed, jjmedinas, gunjan-kumar-mehta, abaikenov, Aigelov, and 37 more reacted with hooray emoji
root-ansh, IsaacDouglas, and Akilesh124 reacted with confused emoji
jodiDL, ProgramCpp, allanshajimanamel-zz, la0rg, G-nsyed, jjmedinas, menporulporiayalan, azizullah2017, benbjurstrom, sanchit-ahuja, and 49 more reacted with heart emoji
abaikenov, Aigelov, silenttoom, jakedub, chrisdamba, DumasOlivier, quency711, achraf-jeday, bj-mcduck, logbasex, and 21 more reacted with rocket emoji
logbasex, riskgod, Aphax, sonlexqt, bhemeswararao, ali-master, fandy, IlanHZ, mv0409, and Akilesh124 reacted with eyes emoji

@tiancaipipi110

ERROR: for iky_gateway Cannot start service iky_gateway: b’driver failed programming external connectivity on endpoint iky_gateway (47d83edbbc1568eae6d26f5e75931797b7e23c6528ff7cc8140f50811fb44922): Error starting userland proxy: Bind for 0.0.0.0:8080 failed: port is already allocated’

I’ve tried docker-compose down, didn’t fix it.

mtrtm, spoonit, otheus, YehuditGrinwald, raquel-campuzano, cooervo, seanghay, anjneeksharma, jolieip, ablajievschii, and 3 more reacted with thumbs up emoji

@PJLindsay

Another solution that may be helpful to future readers is: double-check your docker-compose.yml file and check to make sure you don’t have 2 items attempting to run on port 8080.

If you do have 2 items configured to run on port 8080 you can get «port already allocated» error message for the service/container that is not causing the problem — which will cause you confusion when you try and kill the service/container and get no resolution to the error message.

@timendez

@Rub21’s solution worked for me, except kill -9 {pid} kept restarting the process. This was because I had MySQL Server running. On OSX I had to:

  1. System Preferences
  2. Search for mysql
  3. Press the Stop MySQL Server button
AnandSurkali, tsantos301, dsteinel, sarah-sampan, valdesekamdem, gabrielpittacosta, firaskrichi, chaofan232, GustavoFigueira, and PandaonMars reacted with thumbs up emoji
gitkarumuga, almiskea, gmonseur, MichaelWalker-git, MayankJariwala, rowlandekemezie, dsteinel, valdesekamdem, vimmis, and firaskrichi reacted with hooray emoji
kevintroko, saltcod, foridpathan, and jovanvuleta reacted with confused emoji
Tsatia reacted with rocket emoji

@KazibweStephen

I removed port binding and it worked for me, instead of doing
mysql:
ports:
— 3306:3306

i had to change to
mysql:
ports:
— 3306

and all was good.

alvinthen, dondrzzy, IsaacOc, xxxbence, senkadir, jgangso, proudname, richbolen, MarcinGinszt, stevengrimaldo, and 26 more reacted with thumbs up emoji
dadatuputi and ChinaskiJr reacted with thumbs down emoji
88plug, stevengrimaldo, and sgendre reacted with hooray emoji
buseodaci reacted with confused emoji
Nsy, tbrunel, mutumbakato, panique, sgendre, and zineddine30 reacted with heart emoji
stevengrimaldo and Nsy reacted with rocket emoji

@joseph-luketelo

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
Then remove any existing data e.g docker volume rm docker_db_data
docker-compose up

DiegoRamires, hnrklssn, vlabs, jakedub, joseph-luketelo, MuTLY, raquel-campuzano, OwenMyers, Vadlusk, jmduarte, and 20 more reacted with thumbs up emoji
Vadlusk, khinmayoo, j-funk, digitlimit, and aljabadi reacted with hooray emoji
Vadlusk and j-funk reacted with heart emoji
digitlimit and darul75 reacted with rocket emoji

@otheus

Same problem here. I am using docker version 17.05.0-ce, build 8965be, with docker-compose 1.13.0 and 1.22.0. The compose-yml file is 3.2.

With apologies to @KazibweStephen , this is not a useful solution. You are telling docker-compose to pick an abritrary port for clients to connect to the container’s mysql service. You might as well tell mysql not to listen to any port or just remove the port configuration altogether.

I have tried various solutions above, including rebooting the server. No other containers are running, and there are no conflicts in the yml file. I recall that this worked in a much older version of docker/compose. netstat -anp on the host shows nothing listening on the ports.

If I completely reomve the ports sections, the processes start up OK. I then use nsenter ... netstat to verify the container is listening in on the correct port (in its namespace). I then check with netstat to verify there is no conflict on the default namespace. I can then use a utility such as nc to listen on the same port.

I can see no reason vis-a-vis the documentation why the configuration does not work. The conclusion is there is something wrong with docker-compose’s proxy setup.

Unbelievable. I had, in fact, a tiny error which caused the problem. My configuration needed two ports, and one of these had a typo, replicating the other. facepalm

@wonmaungthein

netstat | grep 5432?

Hi, when I run this, I got this message..

98808d86b49cff5d stream 0 0 98808d86b6dd9be5 0 0 0 /tmp/.s.PGSQL.5432. Can you please help me what to do ? Thanks

@straurob

and in my case the fix was simply to disable the port binding, that is changing the last part as:

Not sure if this is the right solution, nor if it can be generally applied to all use cases.

Might it be an issue with docker-compose itself ?
For reference:

$ docker-compose --version
docker-compose version 1.12.0, build b31ff33

This fix worked for me.


docker-compose -version
docker-compose version 1.23.1, build b02f1306

@maritaria

I had a slightly different situation, posting here to record another case of this happening.

When using a docker-compose.yml and docker-compose.override.yml file, which both contain a port mapping, where the host port is the same for both mappings, but the container port differs, then this causes docker to try and allocate the host port twice.

docker-compose.yml:

docker-compose.override.yml:

Perhaps this is an issue on its own, creating overriding mappings results in duplicate binding attempts. This situation is specifically narly because nothing is listening on the port until you attempt to bring the containers online. Which fails and therefor shuts down the entire composition, which results in the port becoming un-allocated again.

@Devether15

The solution of @lorenzo-pasa worked for me! I’m using docker-compose and nginx, running ubuntu OS, thanks dude.

@Ezwen

I am curious: why is this issue closed, while numerous people still seem to encounter a problem(including myself)? Is the official fix to never write (for instance) 8080:8080 and to always write instead simply 8080? Just to be clear this is not a complaint I am sincerely curious.

IvoPereira, rosshadden, selwynpolit, igauravsehrawat, domsleee, hhimani, freesoft, pmrt, c0d3ster, spiritualized, and 22 more reacted with thumbs up emoji

@drauscher

@Ezwen agree
I tried out all of the suggestions posted above but still running in errors.
I’m running PHPstorm and try to Xdebug my application in a dockerbox. When starting the my dockerbox i am using docker-compose up with a

ports:
— «9001:9001»

which exposes the port correctly. (vpnkit.exe is a part of Docker)
grafik

I see that vpnkit.exe is listening to port 9001. So when I now try to start my Xdebug in PHPstorm it comes up with the error message
grafik

I don’t know why I can’t tell the PHPstorm debugger to listen to port 9001 while it is always used by vpnkit.exe when I start my docker container?

fureigh

pushed a commit
to 18F/nsf
that referenced
this issue

Jan 16, 2019

@marcosleonel

Thanks, @lorenzo-pasa ! That was exactly my problem and your solutions worked. I tried a lot of stuff to solve this with no result. Thank you, again!

I ran into the same issue today (with a postgres container), and despite having tried docker-compose down and then up again, the problem still persists.

Both docker-compose ps and docker ps show me an empty output.

I may have found a solution, though:

this is how my postgres service is defined

version: '2.1'

services:

  postgres:
    image: postgres:9.5.4
    env_file:
      - docker-compose.env
    ports:
      - 5432:5432

and in my case the fix was simply to disable the port binding, that is changing the last part as:

Not sure if this is the right solution, nor if it can be generally applied to all use cases.

Might it be an issue with docker-compose itself ?
For reference:

$ docker-compose --version
docker-compose version 1.12.0, build b31ff33

@kmturley

For me the issue was another docker container was still running in the background from a different project.

I fixed by running:

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
arditsinani, MuTLY, netojose, unitsp, nacosta-cl, MarijaTaseva, Epotignano, vitalbone, irenesacchi, geetotes, and 40 more reacted with thumbs up emoji
netojose, Epotignano, irenesacchi, ckim16, davidsmandrade, GuillaumeOcculy, and exsesx reacted with hooray emoji
netojose, divinentd, Epotignano, irenesacchi, AnneNamuli, GuillaumeOcculy, and exsesx reacted with heart emoji

@freesoft

I have a same issue as @maritaria mentioned about.

@shin-

@freesoft It’s probably best to open a new issue for this.

@abhishekpalavancha

I tried everything here but nothing seems to work then i did this:

sudo lsof -i -P -n | grep 5432

kill all the processes
sudo kill

then it worked for me.

@mikaelhg

Had the same issue with

 Version:           18.09.3
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        774a1f4
 Built:             Thu Feb 28 06:53:11 2019
 OS/Arch:           linux/amd64
 Experimental:      false

One of the docker-proxy processes was hanging, so killing it and systemctl restart docker solved the issue.

zorkyy, jasonlewis, xtfs, smoothdvd, mordredz, dom3k, nickclyde, rogeres19, OkkioXavier, mrcoles, and 9 more reacted with thumbs up emoji

@Shirish-Singh

I ran docker system prune (be cautious with this command) and then restarted docker, it worked for me.

@vardhanaav

If you’re on WSL2, check to see if Hyper-V is enabled or not. If it isn’t, just enable it, that’ll do.

@asannikov

@Keegan-y

I removed port binding and it worked for me, instead of doing
mysql: ports: — 3306:3306
i had to change to
mysql: ports: — 3306
and all was good.

Solution above was what I needed, thanks a lot @KazibweStephen

@jis0324

I combined the answers of everybody.

docker-compose down
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
systemctl restart docker
docker-compose up

@zahragolpa

Changing the port from

to

ports:
    - "10080:80"
    - "10443:443"

in the docker-compose.yml file helped me solve this issue.

@asencis

One potential solution for this is you don’t always need to have an external port binding in your docker-compose.yml file:

Should be sufficient for postgres, as you only really want container <=> container interactions for development. (You shouldn’t be shipping your DB in a container tho for production environments).

@Chocofede

@jonasaud93

Worked for me

docker-compose down
docker network prune
sudo service docker restart
docker-compose up

Thanks! Pruning the network after docker-compose down was the thing that I missed by trying the previous answers.

@plapa

@CsabaNa

@drauscher

@Ezwen agree
I tried out all of the suggestions posted above but still running in errors.
I’m running PHPstorm and try to Xdebug my application in a dockerbox. When starting the my dockerbox i am using docker-compose up with a

ports:

  • «9001:9001»

which exposes the port correctly. (vpnkit.exe is a part of Docker)
grafik

I see that vpnkit.exe is listening to port 9001. So when I now try to start my Xdebug in PHPstorm it comes up with the error message
grafik

I don’t know why I can’t tell the PHPstorm debugger to listen to port 9001 while it is always used by vpnkit.exe when I start my docker container?

Have you had a solution for this problem? I just run into it the xdebug was working fine until yesterday evening then in storm:
Can't start listening for connections from 'xdebug': Port 21003 is busy
and restart the containers:
Cannot start service backend: Ports are not available: listen tcp 0.0.0.0:21003: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
literally i changed nothing one run worked the other started to fail.

compose file:

backend:
image: backend
links:
— «bc2db»
depends_on:
— bc2db
ports:
— «21443:443»
— «2180:80»
— «21000:8000»
— «21003:9003»

gateway:
image: gateway
links:
— «bc2db»
depends_on:
— bc2db
ports:
— «23443:443»
— «2380:80»
— «23003:9003»

All of which are working except the xdebug. All the solution what were mentioned here have been tried none of them works for me. The confusion is this was working in one secundes and suddenly stopped everything in the next one.

@al-yakubovich

In my case I had this problem because there were two replicas in my compose file:

version: '3'
services:
    web:
        build: .
        ports:
            - "5000:5000"
        deploy:
            replicas: 2

When I’ve changed a number of replicas to one, docker-compose up started working

@chris-aeviator

I don’t see why this issue has been closed. Pruning networks or forcefully restarting docker daemon is a workaround for a bug — it’s not that the bug went away, it’s just people embraced workarounds.

This happens quite often on multiple machines and looks like a bug, though not an easy to reproduce one

@JANHMS

I had the same problem two times now….
I tried the solutions of above, but none seemed to help me. I restarted and it did not work. Hence I shut my MAC fully down and manually restarted it. Finally docker-compose up worked without any problems.
-> Sometimes restarting is a simple but effective solution :-D

@jis0324

I don’t see why this issue has been closed. Pruning networks or forcefully restarting docker daemon is a workaround for a bug — it’s not that the bug went away, it’s just people embraced workarounds.

This happens quite often on multiple machines and looks like a bug, though not an easy to reproduce one

Yes, My thought also is same as you.
As we can see. many developers got this problem.
I think this problem has to solve as programmatically.

@yassinelachgar

For me the issue was another docker container was still running in the background from a different project.

I fixed by running:

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Doing this, then restarting docker engine & docker-compose up worked for me.

@otheus

For me the issue was another docker container was still running in the background from a different project.
I fixed by running:

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Doing this, then restarting docker engine & docker-compose up worked for me.

That’s not really a solution in a production environment :-/

@yassinelachgar

For me the issue was another docker container was still running in the background from a different project.
I fixed by running:

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

Doing this, then restarting docker engine & docker-compose up worked for me.

That’s not really a solution in a production environment :-/

Fortunately I’ve never encountered this error on my production environment, only on my local dev env (macos).

@jaime2505

Thanks @olfamoussaoui, that work for me

if you are using Windows you need to run the following command:
docker-compose down
netstat -ano | findstr :port ( as example netstat -ano | findstr :18080)
taskkill /pid the_pid_of_the_port /f
docker-compose up
And that’s it 😄

@halindraprakoso

what worked for me:

docker-compose down
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
launchctl list | grep docker
launchctl stop com.docker.docker.<number>

@nicu-chiciuc

so I’m not sure if this is a fluke, but for some reason after I quit Spotify it seemed to work. I’ve tried most of the solutions above before that

@MikeB2019x

docker-compose down docker stop $(docker ps -a -q) docker rm $(docker ps -a -q) launchctl list | grep docker launchctl stop com.docker.docker.<number>

Yes, this works but make sure you know what ‘launchctl’ does (it stops docker but that doesn’t clear up the problem per se as starting/stopping docker alone did not stop the error from reappearing). The important part is the ‘docker rm’ because it seems to remove the port allocation that docker is perceiving (likely deleting some reference in docker). For example, this ‘docker-compose.yml’ of mine (below) suddenly stopped launching with the error that port 5665 was already allocated even with no containers running in my system. docker compose down/stop/rm seemed to clear whatever was making docker think the port was already allocated.

version: "3"
services:
  postgres:
    image: postgres:13
    container_name: graphstruct_db
    volumes:
      - ./graphstruct:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=graphstruct_data
    ports: 
      - 5665:5432
volumes:
  graphstruct:

@GCSBOSS

I’m having this issue in Docker Compose version v2.6.0

Mentioned in #9117

@lfabl

If you use windows and if non of them worked, Delete your relevant container in Docker. Then right click on docker tray icon at the bottom right of the screen and close docker. Try run again.

@wilokecom

I ran into the same issue today (with a postgres container), and despite having tried docker-compose down and then up again, the problem still persists.

Both docker-compose ps and docker ps show me an empty output.

I may have found a solution, though:

this is how my postgres service is defined

version: '2.1'

services:

  postgres:
    image: postgres:9.5.4
    env_file:
      - docker-compose.env
    ports:
      - 5432:5432

and in my case the fix was simply to disable the port binding, that is changing the last part as:

Not sure if this is the right solution, nor if it can be generally applied to all use cases.

Might it be an issue with docker-compose itself ? For reference:

$ docker-compose --version
docker-compose version 1.12.0, build b31ff33

You saved my day

Содержание

Введение
Bind for 0.0.0.0:80 failed: port is already allocated
the input device is not a TTY
ls: cannot access
Got permission denied while trying to connect to the Docker daemon socket
unable to prepare context: context must be a directory
Error response from daemon: unable to find user andrei: no matching entries in passwd file
Статьи про Docker

Введение

В этой статье вы можете найти ошибки с которыми я встретился при работе с

Docker

Инструкции по работе с Docker можете прочитать

здесь

и

здесь

Bind for 0.0.0.0:80 failed: port is already allocated.

docker: Error response from daemon: driver failed programming external connectivity on endpoint web (8b4ccb280aa958668c714013462f1a84334118d41bbd5505e7bfdc23331c2ce5): Bind for 0.0.0.0:80 failed: port is already allocated.

Скорее всего у Вас уже запущен контейнер который слушает порт 80

Выполните

docker ps -a

Посмотрите какой контейнер из тех что Up использует порт 80 — это видно в столбце PORTS

Остановите его командой

docker stop имя_контейнера

Обратите внимание на то, что имя контейнера может не совпадать с именем образа. Вам нужен столбец NAMES

Похожая ошибка

docker: Error response from daemon: driver failed programming external connectivity on endpoint quirky_khayyam (ee99ee75b322c083c0f2e34395785fa23d2217a7f21fb62c6acf9d6f10ffd68b): Error starting userland proxy: listen tcp4 0.0.0.0:5000: bind: address already in use.

the input device is not a TTY

the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty’

Скорее всего вы пытаетесь запустить, например,

ubuntu

в docker под

Windows
. Например

docker exec -it myubuntu bash

Попробуйте последовать совету и выполнить

winpty docker exec -it myubuntu bash

ls: cannot access

ls: cannot access ‘C:/Program Files/Git/’: No such file or directory

Скорее всего у вас запущен, например, ubuntu в docker под

Windows
и вы пытаетесь выполнить какую-то команду внутри контейнера используя /

docker exec myubuntu ls /

или

docker exec myubuntu cat /data.txt

Попробуйте выполнить без /

docker exec myubuntu ls

или

docker exec myubuntu cat data.txt

Got permission denied

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See ‘docker run —help’.

Возможно, пользователь который запускает docker run не состоит в группе docker.

Проверить есть ли группа docker можно командой

groups

andrei adm cdrom sudo dip plugdev lpadmin lxd sambashare docker

Если группа docker уже есть — переходите к следующему шагу. Если её нет — создайте командой

sudo groupadd docker

Нужно добавить пользователя в группу docker командой

sudo usermod -aG docker username

Осталось только перелогиниться и всё должно заработать

Если не помогло — выполните дополнительно

newgrp docker

Подробнее про администрирование пользователей и групп в

Linux

читайте в статье

«Пользователи Linux»

unable to prepare context: context must be a directory

unable to prepare context: context must be a directory: /home/andrei/docker/Dockerfile

Обычно эта ошибка возникает при неудачной попытке явно указать какой

Dockerfile

нужно использовать для

сборки

контейнера.

Пример правильного указания докерфайла с помощью опции -f

docker build -t andrei-debian:1.0 -f Dockerfile-debian .

Подробности о сборке контейнеров читайте в статье

docker build

debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can’t locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.30.0 /usr/local/share/perl/5.30.0 /usr/lib/x86_64-linux-gnu/perl5/5.30 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.30 /usr/share/perl/5.30 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7, <> line 18.)
debconf: falling back to frontend: Teletype
dpkg-preconfigure: unable to re-open stdin:

Configuring tzdata
——————

Please select the geographic area in which you live. Subsequent configuration
questions will narrow this down by presenting a list of cities, representing
the time zones in which they are located.

1. Africa 6. Asia 11. System V timezones
2. America 7. Atlantic Ocean 12. US
3. Antarctica 8. Europe 13. None of the above
4. Australia 9. Indian Ocean
5. Arctic Ocean 10. Pacific Ocean
Geographic area:

После ввода зависает

docker.io : Depends: containerd

При попытке установить Docker в

Ubuntu

sudo apt install docker.io

Возникает ошибка

Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
docker.io : Depends: containerd (>= 1.2.6-0ubuntu1~)
E: Unable to correct problems, you have held broken packages.

Нужно обновить apt и установить containerd

sudo apt -y update

sudo apt -y upgrade

sudo apt -y install containerd

Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
runc
The following packages will be REMOVED:
containerd.io docker-ce
The following NEW packages will be installed:
containerd runc
0 upgraded, 2 newly installed, 2 to remove and 0 not upgraded.
Need to get 36.9 MB of archives.
After this operation, 45.6 MB disk space will be freed.
Get:1 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 runc amd64 1.1.0-0ubuntu1~20.04.1 [3,892 kB]
Get:2 http://fi.archive.ubuntu.com/ubuntu focal-updates/main amd64 containerd amd64 1.5.9-0ubuntu1~20.04.4 [33.0 MB]
Fetched 36.9 MB in 5s (7,316 kB/s)
(Reading database … 254483 files and directories currently installed.)
Removing docker-ce (5:20.10.18~3-0~ubuntu-focal) …
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
Removing containerd.io (1.6.8-1) …
Selecting previously unselected package runc.
(Reading database … 254461 files and directories currently installed.)
Preparing to unpack …/runc_1.1.0-0ubuntu1~20.04.1_amd64.deb …
Unpacking runc (1.1.0-0ubuntu1~20.04.1) …
Selecting previously unselected package containerd.
Preparing to unpack …/containerd_1.5.9-0ubuntu1~20.04.4_amd64.deb …
Unpacking containerd (1.5.9-0ubuntu1~20.04.4) …
Setting up runc (1.1.0-0ubuntu1~20.04.1) …
Setting up containerd (1.5.9-0ubuntu1~20.04.4) …
Processing triggers for man-db (2.9.1-1) …

docker run -d -p 5000:5000 productservice

docker: Error response from daemon: unable to find user andrei: no matching entries in passwd file.

При попытке установить Docker в

Ubuntu

docker: Error response from daemon: unable to find user andrei: no matching entries in passwd file.

Похожие статьи

Docker
Установка в Linux и Windows
Основы
images: Образы
build: Создание контейнеров + примеры
run: Опции запуска контейнера
Dockerfile
Остановить/удалить все контейнеры
exec: выполнить команду в контейнере
docker compose
Установка docker compose в Linux
Видеоуроки
Ошибки
Make
  • Garry Marsland

May 29, 2018
3 min read

If you notice that a mapped port is taking too long to respond or not working then there are a number of steps you can take to see what’s going wrong.

Take a look at what’s running

On the host execute a docker ps -a.

Do you see your container running in the output list?

If it isn’t there then it’s likely that it didn’t start correctly. You may want to check your command is correct for starting your container. Also check the output for the start command, you may see something like:

Bind for 0.0.0.0:80 failed: port is already allocated.

Which means that the host is already allocated that port to another application or Docker container.

I can see my container in the output list

If you can see your container in the output from docker ps -a what does the status say? If it says Exited (0) X seconds ago then it looks like the main process exited. This could mean that your application shut down prematurely or an error occurred that caused it to fail. The logs of the container might be able to give you a bit more information with docker logs <container-id>.

My container is still running

If the status is Up X seconds then it’s alive! Great news! Let’s take a look at the ports column.

A good port binding for 80 will look something like 0.0.0.0:80->80/tcp. This is saying that 0.0.0.0:80 (the host IP address from the container’s perspective) on port 80 is being routed -> to port 80 on the container for the tcp protocol.

If you notice that the ports column for your container is empty or says something like 80/tcp then be aware that the port binding has not been set up correctly. Double check that your Docker run command is correct and that the -p argument is in the right place!

Beware you can’t specify the -p parameter anywhere. The following two commands are not the same thing:
docker run -d <image-name> -p 80:80 (Wrong)
docker run -d -p 80:80 <image-name> (Right)

Everything looks okay but it still doesn’t work

If everything looks correct and you’re still not able to get a response then it’s time to connect to the container to see whether the application itself is listening on the specified port. Use the following to connect to the running container:

docker exec -it <container-id> bash

(If you have any issues then the instructions on How to Connect to a Running Container go into a little more depth and provide some troubleshooting help.)

We’re in!

The idea once we’re inside is to make a request to the port that our application is supposed to be listening on and see what response we get. The best way of doing this is by using curl:

curl -I http://localhost:<port-number>

Make sure you replace the <port-number> above with the port number the application is listening on NOT the port you bound in Docker.

In this output you’ll hopefully see something like

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0HTTP/2 200

This will give you the status code of the response. If you get a Failed to connect to localhost port <port-number>: Connection refused then it doesn’t look like the application is listening on that port. Obviously change the curl request to reflect how your application responds.

If all else fails

Sometimes Docker just gets into a funky state and stops working. I’d suggest if you’ve got to this stage you consider the ol’ turn it off and on again solution by restarting the docker engine.

service docker restart

If this still doesn’t work, give the server a kick.

I hope this helps some of you debugging Docker port bindings.

Have fun!

Понравилась статья? Поделить с друзьями:
  • Port 5500 vs code как исправить
  • Plants vs zombies как изменить разрешение экрана
  • Popup error css
  • Plants vs zombies goty edition как изменить разрешение
  • Php set error 500