简体   繁体   中英

Docker windows Ports are not available:

New to Docker. I am running Visual Studio 2019 community on Win 10 machine. Installed Docker desktop and created two solutions (service1 and service2). I am trying to run both of the solutions on their own containers.

I was able to build and run service1 using:

docker run -it --rm -p 3000:80 --name mymicroservicecontainer mymicroservice

Question what is 3000:80? is 80 a port? because I was able to run my api using http://localhost:3000/api/product/1 from browser.

Next, I am trying to run service2 on it's own container by:

docker run -it --rm -p 2000:80 --name myanotherservicecontainer myanotherservice

Since the port is 2000, I guess it should work however I get following error:

docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:2000: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

time="2020-04-08T14:22:41-04:00" level=error msg="error waiting for container: context canceled"

Is that because I have:80 same as service1? What is the solution? I am running commands on admin mode in command prompt.

Please help. Thank you.

docker run -it --rm -p 3000:80 --name mymicroservicecontainer mymicroservice

Answer to your first question is YES , 80 is a port. Basically what -p 3000:80 does is that it maps TCP port 80 in the container to port 3000 on the Docker host.

The error you are getting for services is because port 2000 is occupied some other process. It's clearly mentioned in the error message as well.

docker: Error response from daemon: Ports are not available

If you try to map it to some other port(that is free on your machine), then it would work as expected.

Maybe try -p 1111:80 or -p 1234:80

Readthis for more detail on docker container networking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM