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 ?
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.
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.
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.
Add a line to your DockerFile before restarting apache.
RUN echo 'ServerName localhost' >> /etc/apache2/apache2.conf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With