Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localhost not working in docker for mac

I am using latest Docker for mac. I am running into this strange issue. I can access my webapp via http://127.0.0.1/ but not http://localhost/ however I can access https://localhost/ (self signed cert). So, I am not sure what is wrong here.

This is my docker compose.

version: "3"
services:
  php:
    build:
      context: .
    container_name: php
    volumes:
      - .:/var/www/html
      - conf:/etc/apache2/sites-enabled
    ports:
      - "80:80"
      - "443:443"

and this is my Apache config

<VirtualHost _default_:80>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/html

  <Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

<IfModule mod_ssl.c>
  <VirtualHost _default_:443>
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    SSLEngine on
    SSLCertificateFile /etc/apache2/certs/localhost.crt
    SSLCertificateKeyFile /etc/apache2/certs/localhost.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>

    <Directory /usr/lib/cgi-bin>
        SSLOptions +StdEnvVars
    </Directory>

    BrowserMatch "MSIE [2-6]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

  </VirtualHost>
</IfModule>
like image 575
nicholasnet Avatar asked Aug 07 '17 01:08

nicholasnet


2 Answers

You can try with docker.for.mac.localhost

like image 124
Nilesh Gule Avatar answered Oct 27 '22 00:10

Nilesh Gule


Just putting @danwild comment in answer form for more visibility.

You can now access localhost from within the container using host.docker.internal. See the docs

like image 45
lights Avatar answered Oct 26 '22 22:10

lights