title: How to cure 503 Service Unavailable in Apache running in Docker Container?
body: <p>I am trying to create an Apache virtual host proxy in a Docker container (I am on Docker 1.6), so I did the following:</p>
  <p>First set up two Docker containers, each running their own web application:</p>
  <pre><code>docker run -it -p 8001:80 -p 4431:443 --name build ubuntu:latest
  
  apt-get update
  apt-get install apache2 libapache2-mod-php -y
  echo “&lt;?php phpinfo(); ?&gt;” &gt;&gt; /var/www/html/info.php
  service apache2 restart
  </code></pre>
  <p>then</p>
  <pre><code>docker run -it -p 8002:80 -p 4432:443 --name cicd ubuntu:latest
  
  apt-get update
  apt-get install apache2 libapache2-mod-php -y
  echo “&lt;?php phpinfo(); ?&gt;” &gt;&gt; /var/www/html/info.php
  service apache2 restart
  </code></pre>
  <p>Each of these runs perfectly on their respective ports. So next I create a container running Apache:</p>
  <pre><code>docker run -it -p 8000:80 -p 4430:443 --name apache_proxy ubuntu:latest
  
  apt-get update
  apt-get install apache2 -y
  a2enmod proxy
  a2enmod proxy_http
  service apache2 restart
  </code></pre>
  <p>This works perfectly on it's own at port 8000.</p>
  <p>Then I created a virtual host file for each of the other Docker containers:</p>
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName build.example.com
      &lt;Proxy *&gt;
          Allow from localhost
      &lt;/Proxy&gt;
      ProxyPass / http://localhost:8001/
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>and</p>
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName cicd.example.com
      &lt;Proxy *&gt;
          Allow from localhost
      &lt;/Proxy&gt;
      ProxyPass / http://localhost:8002/
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>Then placed both in <code>/etc/apache2/sites-available/</code> of the <code>apache_proxy</code> container.</p>
  <p>Now, I went back into the <code>apache_proxy</code> container and performed the following:</p>
  <pre><code>a2ensite build.example.conf
  a2ensite cicd.example.conf
  service apache2 restart
  </code></pre>
  <p>Running <code>apachectl -S</code> from the command line of the <code>apache_proxy</code> container I can see the following is in effect:</p>
  <pre><code>VirtualHost configuration:
  *:80 is a NameVirtualHost
       default server 172.17.0.17 (/etc/apache2/sites-enabled/000-default.conf:1)
       port 80 namevhost 172.17.0.17 (/etc/apache2/sites-enabled/000-default.conf:1)
       port 80 namevhost build.example.com (/etc/apache2/sites-enabled/build.example.conf:1)
       port 80 namevhost cicd.example.com (/etc/apache2/sites-enabled/cicd.example.conf:1)
  </code></pre>
  <p>Here is what the setup looks like:
  <a href="https://i.stack.imgur.com/Irwtu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Irwtu.png" alt="Docker VHost Example" /></a></p>
  <p>I can reach each individual container via it's respective port and I should be able to go to the following URL's to get to the respective sites:</p>
  <p>build.example.com:8000 should proxy to the container/website on port 8001
  cicd.example.com:8000 should proxy to the container/website on port 8002</p>
  <p>Instead I get the following error:</p>
  <blockquote>
  <p>503 Service Unavailable</p>
  </blockquote>
  <p>Checking the logs I get the following:</p>
  <pre><code>[Mon Oct 16 21:17:32.510127 2017] [proxy:error] [pid 165:tid 140552167175936] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
  [Mon Oct 16 21:17:32.510278 2017] [proxy:error] [pid 165:tid 140552167175936] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
  [Mon Oct 16 21:17:32.510302 2017] [proxy_http:error] [pid 165:tid 140552167175936] [client 172.26.16.120:61391] AH01114: HTTP: failed to make connection to backend: localhost
  [Mon Oct 16 21:17:32.799053 2017] [proxy:error] [pid 166:tid 140552217532160] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8001 (localhost) failed
  [Mon Oct 16 21:17:32.799232 2017] [proxy:error] [pid 166:tid 140552217532160] AH00959: ap_proxy_connect_backend disabling worker for (localhost) for 0s
  [Mon Oct 16 21:17:32.799256 2017] [proxy_http:error] [pid 166:tid 140552217532160] [client 172.26.16.120:61392] AH01114: HTTP: failed to make connection to backend: localhost, referer: http://build.example.com:8000/info.php
  </code></pre>
  <p>I have been going down rabbit holes for the past several hours trying to get this to work and I am sure now I am missing something quite simple. Can anyone shed light on the error of my ways?</p>
  <h2>NOTE</h2>
  <p>I followed a huge rabbit hole concerning SELinux which is not enabled or even really installed in the Ubuntu/Apache proxy container.</p>
  <p>I should also state that I am not a network guru or master web-server configurator. I only know enough to be dangerous.</p>
  <h2>EDIT</h2>
  <p>Based on suggestions I have tried the following:</p>
  <p><code>ProxyPass / http://cicd:80/</code> causes a 502 error<br />
  <code>ProxyPass / http://ip.address.of.server:8002/</code> times out<br />
  <code>ProxyPass / http://ip.address.of.container:8002/</code> causes a 503 error<br />
  <code>ProxyPass / http://127.0.0.1:8002/ retry=0</code> causes a 503 error (suggested in other answers)<br /></p>