Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

  • Create a swarm manager (and a worker) node
  • Find out the ip address of your swarm manager node (usually 192.168.99.100): docker-machine ip manager or docker-machine ls. Edit your hosts file (on a Mac, sudo vi /private/etc/hosts) by adding 192.168.99.100 project.dev and 192.168.99.100 api.project.dev
  • git clone https://github.com/thomastilkema/docker-nginx-php-fpm-node project
  • cd project ./scripts/up.sh
  • Have a look at the logs of the container: docker logs <container-id> -f
like image 723
Thomas Avatar asked May 04 '26 05:05

Thomas


1 Answers

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')
like image 107
Matt Avatar answered May 05 '26 19:05

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!