Thomas
Thomas

Reputation: 33

Docker: can not communicate between containers

I have a Docker setup with a php-fpm container, a node container and an nginx container which serves as a proxy. Now in the browser (http://project.dev), the php container responds with json like I expect. All good. However, when I make a request from the node container to this php container (view code), I get an error on the request: ECONNRESET. So apparently, the node container can not communicate with the php container. The nginx error does not seem to add an entry.

Error: read ECONNRESET at _errnoException(util.js: 1031: 13) at TCP.onread(net.js: 619: 25)
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read'

Any ideas?

I've made a github repo: https://github.com/thomastilkema/docker-nginx-php-fpm-node

Trimmed version of docker-compose.yml (view file)

nginx:
  depends_on:
    - php-fpm
    - node
  networks:
    - app
  ports:
    - 80:80

php-fpm:
  networks:
    - app

node:
  networks:
    - app

networks:
  app:
    driver: overlay

Trimmed version of nginx.conf (view file)

http {
  upstream php-fpm {
    server php-fpm:9000;
  }

  upstream node {
    server node:4000;
  }

  server {
    listen 80 reuseport;
    server_name api.project.dev;

    location ~ \.php$ {
      fastcgi_pass php-fpm;
      ...
    }
  }

  server {
    listen 80;
    server_name project.dev;

    location / {
      proxy_pass  http://node;
    }
  }
}

php-fpm/Dockerfile (view file)

FROM php:7.1-fpm-alpine

WORKDIR /var/www

EXPOSE 9000

CMD ["php-fpm"]

Request which gives an error

const response = await axios.get('http://php-fpm:9000');

How to reproduce

Upvotes: 3

Views: 983

Answers (1)

Matt
Matt

Reputation: 74889

ECONNRESET is the other end closing the connection which can usually be attributed to a protocol error.

The FastCGI Process Manager (FPM) uses the FastCGI protocol to transport data.

Go via the nginx container, which translates the HTTP request to FastCGI

axios.get('http://nginx/whatever.php')

Upvotes: 1

Related Questions