Running a Docker container that accept traffic from the host

It is saying port 80 is busy ... run this to see who is using port 80

sudo netstat -tlnp | grep 80 # sudo apt-get install net-tools # to install netstat

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1380/nginx -g daemo
tcp6       0      0 :::80                   :::*                    LISTEN      1380/nginx -g daemo

scroll to far right to see offending PID of process holding port 80 ... its PID 1380 so lets do a process list to see that pid

ps -eaf | grep 1380

root      1380     1  0 11:33 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

so teardown that offending process to free up the port 80

sudo kill 1380  # if you know the pid ( 1380 for example )

__ or __

sudo fuser -k 80/tcp #  just kill whatever pid is using port 80 tcp

If after doing above its still saying busy then probably the process which you killed got auto relaunched in which case you need to kill off its watcher however you can walk up the process tree from netstat output to identify this parent process and kill that too

Here is how to identify the parent pid of a given process pid

ps -eafww

eve         2720    2718  0 07:56 ?        00:00:00 /usr/share/skypeforlinux/skypeforlinux --type=zygote

in above pid is 2720 and its parent will be the next column to right pid 2718 ... there are commands to show a process tree to visualize these relationships

ps -x --forest  

or

pstree  -p

with sample output of

systemd(1)─┬─ModemManager(887)─┬─{ModemManager}(902)
           │                   └─{ModemManager}(906)
           ├─NetworkManager(790)─┬─{NetworkManager}(872)
           │                     └─{NetworkManager}(877)
           ├─accounts-daemon(781)─┬─{accounts-daemon}(792)
           │                      └─{accounts-daemon}(878)
           ├─acpid(782)
           ├─avahi-daemon(785)───avahi-daemon(841)
           ├─colord(1471)─┬─{colord}(1472)
           │              └─{colord}(1475)
           ├─containerd(891)─┬─containerd-shim(1836)─┬─registry(1867)─┬─{registry}(1968)
           │                 │                       │                ├─{registry}(1969)
           │                 │                       │                ├─{registry}(1970)

If you are running Ubuntu, just run

sudo /etc/init.d/apache2 stop

Then reload your Docker Image

docker reload

The error seems pretty clear:

FATA[0002] Error response from daemon: Cannot start container 67ed31b50133adc7c745308058af3a6586a34ca9ac53299d721449dfa4996657: Error starting userland proxy: listen tcp 0.0.0.0:80: bind: address already in use

It says, "address already in use". This means that something on your system -- probably a web server like Apache -- is already listening on port 80. You will either need to:

  • stop the web server,
  • select a different host port in the -p argument to docker run or
  • just drop the -p argument.

Because Docker can't set up the requested port forwarding, it does not start the container.

Options (a) and (b) will both allow the container to bind to port 80 on your host. This is only necessary if you want to access the container from somewhere other than your host.

Option (c) is useful if you only want to access the container from the docker host but do not want to otherwise expose the container on your local network. In this case, you would use the container ip address as assigned by docker, which you can get by running docker inspect and perusing the output, or just running:

docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_id