I have the following config:
Dockerfile
FROM centos MAINTAINER Eduar Tua <[email protected]> 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:
#!/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?
If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.
You need some DNS to map container ip:s to hostnames. If you want out of the box solution. One solution is to use for example Kontena. It comes with network overlay technology from Weave and this technology is used to create virtual private LAN networks for each service and every service can be reached by service_name.
You can expose a port through your Dockerfile or use --expose and then publish it with the -P flag. This will bind the exposed port to your Docker host on a random port (verified by running docker container ls ). You can expose a port through your Dockerfile or use --expose and then publish it with the -p 80:80 flag.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With