DEV Community

Gahyun Son
Gahyun Son

Posted on

1 1

Docker error: port is already allocated

Where is the port allocated?

I got an error message when I tried docker compose up.

docker compose up
Attaching to app-1
Gracefully stopping... (press Ctrl+C again to force)
Error response from daemon: driver failed programming external connectivity on endpoint hyunphoto-cbv-app-1 (876c605de16e8d99e9e1b806de): Bind for 0.0.0.0:8000 failed: port is already allocated
Enter fullscreen mode Exit fullscreen mode

What did I do before?
I remembered that I had run a project on Docker earlier. That could be cause. Then, how we could check it?

I checked by two steps.
First. Command docker compose down what I ran the project before. I could get the info which container is still running.

! Network hyunphoto-fbv_default  Resource is still in use                                            0.0s 
Enter fullscreen mode Exit fullscreen mode

Second. Command docker network inspect hyunphoto-fbv_default.

[
    {
        "Name": "hyunphoto-fbv_default",
        "Id": "eee2041694529e233c352c6e314",
        "Created": "2024-11-15T14:15:07.24638069Z",
        "Scope": "local", # this network works only in local.
        "Driver": "bridge", # Docker network type. 
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.0.0/16", # IP address of this network.
                    "Gateway": "172.20.0.1" # Gateway IP of this network.
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": { # This container is running.
            "20ea5e895019ac3279ce5009a6": {
                "Name": "hyunphoto-fbv-proxy-1", 
                "EndpointID": "5b86698bc46027072001506a1cd",
                "MacAddress": "02:42:ac:14:00:04", # Mac address allocated to the network interface of a container.
                "IPv4Address": "172.20.0.4/16", # IPv4 address allocated to a container.
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default", 
            "com.docker.compose.project": "hyunphoto-fbv", # Docker compose project name to which this network belongs.
            "com.docker.compose.version": "2.29.2" # Docker Compose version that created the network.
        }
    }
]
Enter fullscreen mode Exit fullscreen mode

Now I know the container that I have to stop.
Solution.

docker stop hyunphoto-fbv-proxy-1
Enter fullscreen mode Exit fullscreen mode

And I can see there is no a container.

apple@GH-MacBook-Pro hyunphoto-fbv % docker network inspect hyunphoto-fbv_default

[
    {
        "Name": "hyunphoto-fbv_default",
        "Id": "eee2041694529e233c352c6e3140aee457c6a33b468b92a33327fd1d39dff5bf",
        "Created": "2024-11-15T14:15:07.24638069Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.20.0.0/16",
                    "Gateway": "172.20.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {}, # HERE!
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "default",
            "com.docker.compose.project": "hyunphoto-fbv",
            "com.docker.compose.version": "2.29.2"
        }
    }
]
Enter fullscreen mode Exit fullscreen mode

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay