Running a Docker container that accept traffic from the host

I have the following config:
Dockerfile

FROM centos  
MAINTAINER Eduar Tua <eduartua@gmail.com>  

RUN yum -y update && yum clean all
RUN yum -y install httpd && yum clean all
RUN echo "Apache works" >> /var/www/html/index.html

EXPOSE 80

ADD run-apache.sh /run-apache.sh
RUN chmod -v +x /run-apache.sh

CMD ["/run-apache.sh"]

The run-apache.sh script:

  • Invoke Docker Remote API using Java
  • Prepare Docker container for worst-case rescue via shell or exec
  • How to configure PHP 7 - Apache with MySQL PDO driver in Debian Docker image?
  • Apache docker container - Invalid command 'RewriteEngine'
  • How can I increase timeouts of AWS worker tier instances?
  • Docker php:5.6-Apache Development Environment missing permissions on volume mount
  • #!/bin/bash
    
    rm -rf /run/httpd/* /tmp/httpd*
    
    exec /usr/sbin/apachectl -D FOREGROUND
    

    Then I build the image with:

    sudo docker build --rm -t platzi/httpd .  
    

    then

    sudo docker run -d -p 80:80 platzi/httpd
    

    After that when I try to run the container accepting connections from the host in the 80 port I get this:

    67ed31b50133adc7c745308058af3a6586a34ca9ac53299d721449dfa4996657
    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
    

    Any help?

  • Microsoft Word crashes when invoking its COM inside Docker Container
  • how to configure docker to be able to use private insecure docker-registry
  • How to mount host volumes into docker containers in Dockerfile during build
  • Is there any workaround for “session deleted because of page crash” Chrome error on Travis CI?
  • How to download file from docker container?
  • Why are my non-volume data in Docker container persistence after restarting the container?
  • 2 Solutions collect form web for “Running a Docker container that accept traffic from the host”

    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
    

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

    netstat -tlnp | grep 80
    
    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
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.