Connect to from one container to another container from diffrent docker-compose

  docker, docker-compose, php

my first docker-compose looks like

version: '3.4'

services:
  php-fpm:
    build:
      context: ./docker
      dockerfile: Dockerfile
      target: php-fpm
    ports:
      - 80:80
      - 443:443
    env_file:
      - .env

and my second docker-compose looks like this:

version: '3.4'

services:
  web:
    build:
      context: ./docker
      dockerfile: Dockerfile
      target: web
    ports:
      - 8080:80

And now I would like to curl from php-fpm container to web container. So I am exectuing this command:

docker-compose exec php-fpm curl http://web:80/

I am getting error:

curl: (6) Could not resolve host: web

When I go to the browser on the host and type address http://localhost:8080 I can see the response from web container.

To summarize: my question is: How to curl from php-fpm container to web container?

PS. In a real project, these docker-compose files look much more complicated and I cannot merge them into one docker-compose file.

Source: Docker Questions

LEAVE A COMMENT