can't access apache on docker from my localhost

13,338

Solution 1

On Windows/OS X, Docker is running inside a Linux virtual machine (Docker Toolbox) with a default IP address of 192.168.99.100. Thus, when you use docker run -p 80:80 to bind the container port to host port, it in fact binds to the virtual machine's port 80. Thus the address you need is http://192.168.99.100.

The 172.17.0.3 address is the address of the docker container inside that virtual machine, and is not accessible directly from Windows/OS X.

Solution 2

Add a line to your DockerFile before restarting apache.

RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
Share:
13,338
a.u.r
Author by

a.u.r

Updated on July 24, 2022

Comments

  • a.u.r
    a.u.r almost 2 years

    I've been following this tutorial for beginners about docker which basically instructs you to create an apache container and map a localhost port to the one on the container. when I try localhost:80 it doesn't connect, although the container is up and running. I even made a rule in the firewall to allow connection to port 80, but couldn't get connected to the localhost.

    Any ideas ?

  • Dazza
    Dazza about 2 years
    It's 2022 and this worked for me.