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:

  • Customise apache.conf - set Timeout
  • Cannot load c:/php/php5apache2_4.dll into server: The specified module could not be found
  • No Space on CentOS with Docker
  • Apache2 Container on BlueMix won't stay up
  • docker+elasticsearch: access is denied when creating the log file
  • docker-py: client and server don't have same version (client : 1.16, server: 1.15)")
  • #!/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?

  • Flocker docker plugin is unable to mount Dataset
  • Docker exits before fork completes execution?
  • Docker Mac Beta and container connecting to host ports?
  • How can I run containers detached and have them automatically removed when they exit?
  • understanding docker volume : can i create a volume and assign it to the specific container /service?
  • Docker composer copy files
  • 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.