Docker: driver failed programming external connectivity on endpoint webserver

During Docker experimentation on Mac ( OS X El Capitan ) by following Docker documentation, some issue happened on step testing Nginx webserver.

$ docker run -d -p 80:80 --name webserver nginx
5794b8cae51cc5246255e2ae5200744153621db63dca91757969c5e6289fcb12
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (0dbb08d2ca72fa574272aa787ad173af50c8e92b712d2d1233c98276214ccba4): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).

The issue was that some other server is using port 80. In my case, the service using port 80 was Apache server.

$ ps -ef | grep httpd
    0    97     1   0 Tue05PM ??         0:09.49 /usr/sbin/httpd -D FOREGROUND
   70   401    97   0 Tue05PM ??         0:00.07 /usr/sbin/httpd -D FOREGROUND
   70  1648    97   0 Tue08PM ??         0:00.07 /usr/sbin/httpd -D FOREGROUND
   70  4600    97   0 Wed01AM ??         0:00.06 /usr/sbin/httpd -D FOREGROUND
   70 13843    97   0 Thu12AM ??         0:00.04 /usr/sbin/httpd -D FOREGROUND
   70 43177    97   0 10:22PM ??         0:00.03 /usr/sbin/httpd -D FOREGROUND
  501 43471 19941   0 10:40PM ttys000    0:00.01 grep httpd

Since I don’t need Apache Server, stopped Apache Server

$ sudo /usr/sbin/apachectl stop

Tried to launch Nginx webserver container, but failed again.

mlees-MacBook-Air:dream mlee$ docker run -d -p 80:80 --name webserver nginx
docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container 5794b8cae51cc5246255e2ae5200744153621db63dca91757969c5e6289fcb12. You have to remove (or rename) that container to be able to reuse that name..

Guessed it might be due to the existing container. So, deleted container.

$ docker container ls --all
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
5794b8cae51c        nginx               "nginx -g 'daemon ..."   11 minutes ago      Created                                 webserver

$ docker rm 5794b8cae51c
5794b8cae51c

Tried again and worked!!

$ docker run -d -p 80:80 --name webserver nginx
8e0481dc0a541c5116a977ba3969c276f135b375ff5de225ce9f0c0d69f63b6f