Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can't access apache on docker from my localhost

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 ?

like image 429
a.u.r Avatar asked Apr 10 '16 14:04

a.u.r


People also ask

How do I make my docker container accessible from localhost?

You just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 . Your host's Docker IP will be shown on the inet line. Connect to this IP address from within your containers to successfully access the services running on your host.

Can I run Apache in docker?

Run your website on Apache in DockerThe dockerized Apache website, which in this case is a friendly little number-guessing game, is now accessible on port 80 in your browser. This dockerized Apache website runs on port 80 of the localhost address.

How do I make my docker talk to localhost?

A simple solution to this in a Linux machine is to use the --network=”host” option along with the Docker run command. After that, the localhost (127.0. 0.1) in your Docker container will point to the host Linux machine. This runs a Docker container with the settings of the network set to host.


1 Answers

Add a line to your DockerFile before restarting apache.

RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
like image 111
Yalcin Yavas Avatar answered Nov 08 '22 07:11

Yalcin Yavas