[Error][MacOS] Ports are not available

Hi All,

I am using MacOS(v14.0) and I tried to perform the following command to run my image:

docker run --rm -ti -p 5900:5900 gui:latest

This is the error I received :

docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:5900 -> 0.0.0.0:0: listen tcp 0.0.0.0:5900: bind: address already in use.
ERRO[0000] error waiting for container:

any solution for this ?

Well, something else is already using the port 5900.

bind: address already in use

Stop the other process or choose a different port.

I don’t think the port is used.

lsof -i -P -a -p 5900 

the command above didn’t return any results.

Did you try netstat -tulpn?

seems you are correct :

netstat -a -n | grep 'LISTEN ' | grep 5900
tcp4       0      0  *.5900                 *.*                    LISTEN     
tcp6       0      0  *.5900                 *.*                    LISTEN

do you know how to figure out those application to close them ?

I also tried :

netstat -anv | egrep -w '[.]5900.*LISTEN'
tcp4       0      0  *.5900                 *.*                    LISTEN       131072  131072      1      0 00180 00000206 0000000000000c1c 00000040 00000900      1      0 000001
tcp6       0      0  *.5900                 *.*                    LISTEN       131072  131072      1      0 00180 00000206 0000000000000c1b 00000040 00000800      1      0 000001

and :

sudo lsof -i -n -P | grep -i '5900'                         
launchd       1           root   11u  IPv6 0x8765f1c7e59b332b      0t0    TCP *:5900 (LISTEN)
launchd       1           root   14u  IPv6 0x8765f1c7e59b332b      0t0    TCP *:5900 (LISTEN)
launchd       1           root   16u  IPv4 0x8765f1d64accf94b      0t0    TCP *:5900 (LISTEN)
launchd       1           root   18u  IPv4 0x8765f1d64accf94b      0t0    TCP *:5900 (LISTEN)

It is better to contact on Apple official website.

I figure out that port 5900 is used by remote desktop sharing. reference : macos - Trying to close open port 5900 or find process that opened it - Ask Different

I am now receiving another error :
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/entrypoint.sh": permission denied: unknown.

this is the content of the entrypoint.sh

#!/bin/bash
x11vnc -forever -usepw -create &
/bin/bash