docker run --name my_first_postgres_9.6 -d -p 127.0.0.1:5432:5432 myaccount/my_postgres_9.6:1.0.0
Nice.
Now I stop container:
docker stop my_first_postgres_9.6
Now create second container
docker run --name my_first_postgres_9.6 -d -p 127.0.0.1:5432:5432 myaccount/my_postgres_9.6:1.0.0
But I get error:
c54c2db0f7496ebf05fcb626496da1a318eab3e4f2
docker: Error response from daemon: Ports are not available: exposing port TCP 127.0.0.1:5432 -> 0.0.0.0:0: listen tcp 127.0.0.1:5432: bind: address already in use.
I need to start second container on the same port.
Is it possible.
Smt like this:
Start first container on port 5432:
Work with first container.
Stop first container on port 5432
Start second container
Please, share the output of the following commands:
docker info
docker version
Stopped containers shouldn’t be a problem when you start another container using the same port, you will just not be able to run both containers at the same time. I couldn’t reproduce your issue with Docker 23.0.1 and Docker 20.10.23 (Docke Desktop for Mac).
The client version is not he same as the server version
The version of Docker Desktop (v4.16.2) is not the latest (v4.17)
My guess is the cause of the issue is the incompatible client or you actually have Docker CE and Docker Desktop on the same machine and somehow you also ran a container in a different context. I reecommend you to upgrade Docker Desktop and downgrade the client to Docker 20.10.*
Before that you can also check the contexts
docker context ls
if you have multiple contexts, switch to the other contexts