title: Docker container running apache always exposing port 80
body: <p>I have a Docker image that runs Apache, and I have configured Apache (through <strong>httpd.conf</strong>) to listen on port <code>8080</code>.</p>
  
  <pre><code>Listen 8080
  </code></pre>
  
  <p>When I build my image and run it, I'm able to successfully connect to my website via port <code>8080</code>, so all seems well at this point.</p>
  
  <pre><code>docker build -t my/apache:8080 .
  docker run --name "MyWebsite" -p 8080:8080 -v ~/dir:/mnt/dir -d -t my/apache:8080
  </code></pre>
  
  <p>However, when I list my running containers using <code>docker ps</code>, I see that port <code>80</code> has also been exposed for some reason.</p>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                            NAMES
  23c4e1f0ea66        my/apache:8080      "/docker-entrypoint.…"   12 minutes ago      Up 12 minutes       80/tcp, 0.0.0.0:8080-&gt;8080/tcp   MyWebsite
  </code></pre>
  
  <p>When I shell on to the running container and search for instances of "Listen 80", nothing shows up other than the instance of "Listen 8080" that I added to <strong>httpd.conf</strong>.</p>
  
  <pre><code>docker exec -it 23c4e1f0ea66 /bin/bash
  grep -ri "Listen 80"
  </code></pre>
  
  <p>My Dockerfile contains only one <code>EXPOSE</code> declaration - <code>EXPOSE 8080</code>. However, I don't believe this actually exposes the port anyway, and is intended more as a way of documenting which port should be exposed when running a container that utilizes the image.</p>
  
  <p>How can I find out when is exposing port <code>80</code>, and crucially, how can I stop it from being exposed?</p>
  
  <h1>Dockerfile</h1>
  
  <pre><code>FROM httpd:2.4
  
  COPY httpd.conf /usr/local/apache2/conf/
  COPY docker-entrypoint.sh /
  
  ENTRYPOINT ["/docker-entrypoint.sh"]
  CMD ["apache"]
  
  ### Apache (proxies to MapProxy).
  EXPOSE 8080
  </code></pre>
  
  <h1>Entrypoint script</h1>
  
  <pre><code>#!/bin/bash
  set -e
  
  if [ "$1" = 'apache' ]; then
          echo "Starting Apache"
          httpd-foreground
  fi
  
  exec "$@"
  </code></pre>
  
  <h1>HTTP config</h1>
  
  <pre><code>ServerRoot "/usr/local/apache2"
  
  Listen 8080
  
  LoadModule mpm_event_module modules/mod_mpm_event.so
  LoadModule authn_file_module modules/mod_authn_file.so
  LoadModule authn_core_module modules/mod_authn_core.so
  LoadModule authz_host_module modules/mod_authz_host.so
  LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
  LoadModule authz_user_module modules/mod_authz_user.so
  LoadModule authz_core_module modules/mod_authz_core.so
  LoadModule access_compat_module modules/mod_access_compat.so
  LoadModule auth_basic_module modules/mod_auth_basic.so
  LoadModule reqtimeout_module modules/mod_reqtimeout.so
  LoadModule filter_module modules/mod_filter.so
  LoadModule mime_module modules/mod_mime.so
  LoadModule log_config_module modules/mod_log_config.so
  LoadModule env_module modules/mod_env.so
  LoadModule headers_module modules/mod_headers.so
  LoadModule setenvif_module modules/mod_setenvif.so
  LoadModule version_module modules/mod_version.so
  LoadModule proxy_module modules/mod_proxy.so
  LoadModule proxy_http_module modules/mod_proxy_http.so
  LoadModule unixd_module modules/mod_unixd.so
  LoadModule status_module modules/mod_status.so
  LoadModule autoindex_module modules/mod_autoindex.so
  &lt;IfModule !mpm_prefork_module&gt;
  &lt;/IfModule&gt;
  &lt;IfModule mpm_prefork_module&gt;
  &lt;/IfModule&gt;
  LoadModule dir_module modules/mod_dir.so
  LoadModule alias_module modules/mod_alias.so
  
  &lt;IfModule unixd_module&gt;
          User daemon
          Group daemon
  &lt;/IfModule&gt;
  
  ServerAdmin applicationdelivery@landmark.co.uk
  ServerName mapproxy.gcs.lmkcloud.net:8080
  DocumentRoot "/usr/local/apache2/htdocs"
  ErrorLog /proc/self/fd/2
  
  LogLevel warn
  
  &lt;IfModule log_config_module&gt;
          LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
          LogFormat "%h %l %u %t \"%r\" %&gt;s %b" common
  
          &lt;IfModule logio_module&gt;
                  LogFormat "%h %l %u %t \"%r\" %&gt;s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
          &lt;/IfModule&gt;
  
          CustomLog /proc/self/fd/1 common
  
  &lt;/IfModule&gt;
  
  &lt;IfModule mime_module&gt;
          TypesConfig conf/mime.types
          AddType application/x-compress .Z
          AddType application/x-gzip .gz .tgz
  &lt;/IfModule&gt;
  
  &lt;IfModule ssl_module&gt;
          SSLRandomSeed startup builtin
          SSLRandomSeed connect builtin
  &lt;/IfModule&gt;
  
  ProxyPreserveHost On
  ProxyPass / http://example.com:8001/ retry=1 acquire=3000 timeout=20 Keepalive=On
  ProxyPassReverse / http://example.com:8001/
  </code></pre>