0

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.

GabrieleMartini
  • 1,665
  • 2
  • 19
  • 26
sasiole
  • 11
  • 3

1 Answers1

1

See

You should configure both the containers on the same network

GabrieleMartini
  • 1,665
  • 2
  • 19
  • 26
  • 2
    Could you add a short example of the proposed solution so this is not a link-only answer? – acran Jul 22 '21 at 09:32