Docker Community Forums

Share and learn in the Docker community.

How to call a local ressource from a container?

I builded : Apache, Php7.3, and Postgresql images with ‘docker-compose.yml’.

Everything works good, but when I make a call of a local photo, I get a warning message and the photo doesn’t appear.

This is the error message :
Warning: getimagesize(https://localhost:80/ failed to open stream: Cannot assign requested address.

I get the same message when I use ‘file_get_contents’ function with ‘localhost’.

Note : calling an external ressource works for theses functions.

So, what must I do to resolve this problem ?


Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0. 0.1 ) will refer to the docker host. … As you can see both the docker host and docker container share the exact same network interface and as such have the same IP address.

Yes, I know that.

I’ve already created a network.
~ All of the containers are sharing the same network (via “docker-compose.yml”). ~

But in my case, I think that the functions used (like : file_get_contents, getimagesize, …etc ) refer to the "localhost/127.0.0."1 of my Host machine, AND not to the network of the container.