When Localhost isn't the Local Host

Let's see what happens when we try to ping localhost from within our PHP container.

We cover a small gotcha that could waste your time.

tl;dr

If your code (e.g. php/php-fpm) is executed on a separate container as your web server (e.g. nginx), then pinging localhost as an HTTP request wont' work, because there's no web server listening for HTTP requests within your code (php) container!

Use the hostname of your Nginx/web server container instead, e.g. http://nginx instead of http://localhost.

https://www.youtube.com/watch?v=L1BDM1oBRJ8

Sign up to get announcements as well as
over 20 free videos on Docker in Development,
a course preview on Dockerizing Your Applications, and more!

What to learn more? Read the blog.

About

the true grumpy programmer, don't be fooled by imitation

I'm Chris Fidao. I wrote the Servers for Hackers eBook, and publish related videos at the Servers for Hackers video site. I also curate the Servers for Hackers newsletter, which is read by over 12,000 programmers who want to learn about servers.

I'm also the author of the Deploy PHP! video series, a video series about automating your deployments. A few years ago, I wrote Implementing Laravel, a book all about coding in Laravel - now offered free!