Docker & Postgres: Failed to bind tcp 0.0.0.0:5432 address already in use

后端 未结 5 1101
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 22:38

Problem

I\'m trying to start postgres in a docker container on my Mac, but I keep getting the following error message

docker: Error response from da

5条回答
  •  臣服心动
    2021-01-30 22:45

    In some cases it is critical to perform a more in-depth debugging to the problem before stopping or killing the container/process.

    Consider following the checklist below:

    1) Check you current docker compose environment
    Run docker-compose ps.
    If port is in use by another container, stop it with docker-compose stop or remove it by replacing stop with rm.

    2) Check the containers running outside your current workspace
    Run docker ps to see list of all containers running under your host.
    If you find the port is in use by another container, you can stop it with docker stop .
    (*) Because you're not under the scope of the origin compose environment - it is a good practice first to use docker inspect to gather more information about the container that you're about to stop.

    3) Check if port is used by other processes running on the host
    For example if the port is 6379 run:

    $ sudo netstat -ltnp | grep ':6379'
    tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      915/redis-server 12 
    tcp6       0      0 ::1:6379                :::*                    LISTEN      915/redis-server 12
    

    (*) You can also use the lsof command which is mainly used to retrieve information about files that are opened by various processes (I suggest running netstat before that).

    So, In case of the output above the PID is 915. Now you can run:

    $ ps j 915
     PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
        1   915   915   915 ?           -1 Ssl    123   0:11 /usr/bin/redis-server 127.0.0.1:6379
    

    And see the ID of the parent process (PPID) and the execution command.
    You can also run: $ pstree -s to a visual display of the process and its related processes (install with: brew install pstree).

    In our case we can see that the process probably is a daemon (PPID is 1) - In that case consider running:
    A) $ cat /proc//status in order to get a more in-depth information about the process like the number of threads spawned by the process, its capabilities, etc'.
    B) $ systemctl status in order to see the systemd unit that caused the creation of a specific process. If the service is not critical - you can stop and disable the service.

    4) Restart Docker service
    Run sudo service docker restart.

    5) You reached this point and..
    Only if its not placing your system at risk - consider restarting the server.

提交回复
热议问题