DEV Community

Gahyun Son
Gahyun Son

Posted on

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

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay