1

I have created an nginx container that is open to port 8080:80 so I could access it from the host.

it is connected to php fpm container that has an open port 9000:9000

nginx successfully runs with php.

My problem is that php tries to access localhost:8080 but the problem is that the php localhost:8080 is not valid, it needs to connect to the nginx container.

here is the error on my wordpress site: you can see that something is funky there... below I'll attach my docker-compose.yml


Downloading install package from http://localhost:8080/wp-content/themes/realtyspace/plugins/advanced-custom-fields-pro.zip

Download failed. cURL error 7: Failed to connect to localhost port 8080: Connection refused


docker-compose.yml

version: '2'
services:
  my-nginx:
    build: .
    volumes:
      - ./../:/var/www/html
    ports:
      - "8080:80"
    links:
      - my-php

  my-php:
    build:
      context: .
      dockerfile: Dockerfile.php-fpm
      volumes:
        - ./../:/var/www/html
      ports:
        - "9000:9000"
      links:
        - my-mysql

  my-mysql:
    image: mariadb:5.5
    volumes:
      - /var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: wp
      MYSQL_DATABASE: wp
      MYSQL_USER: wp
      MYSQL_PASSWORD: wp
3
  • Are you running this directly on Linux or using Docker for Windows/Mac? Commented Nov 10, 2016 at 1:32
  • I'm using docker on Mac, thanks Commented Nov 10, 2016 at 6:14
  • So you have a circular reference in that nginx needs to talk to php and php needs to talk to nginx? Commented Nov 10, 2016 at 21:28

1 Answer 1

1

Use docker's internal networking and configure php to access http://my-nginx:80.

localhost will resolve to the isolated IP of the php container itself, not that of the Docker host that's running everything. And trying to pass http://dockerhost:8080 will result in a non-portable docker-compose.yml and likely issues with iptables firewall and nat rules that are more trouble than they are worth. The value of using the v2 compose files is that you get an isolated network internal to Docker with DNS resolution of each of your containers to work with each other.

Sign up to request clarification or add additional context in comments.

2 Comments

but the php code tries to access that url, just because of the url no? if I have gave it a url of example.com, it will simply try to fetch from there no?
I'm not sure what php code you're running, would need a lot more detail in your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.