Unable to access Docker container from other Docker container

my compose.yml

  volumes_from:
      - appdata
    env_file:
      - ./docker/global.env
      - ./docker/config.env
      - ./docker/composer.env

  web:
    image: shiftedreality/cloud-docker-nginx:1.9
    ports:
      - "8080:80"
    links:

And my .travis.yml:

dist: focal
git:
  depth: 1
services:
  - docker
language: generic

When I try to run file_get_contents('http://web') from cli container, throws an error

Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known to the container.

this works locally

If you are trying to connect to the web container from another container, you’d have to define the host name web on that container and not on the host running your Docker containers (which you did with the hosts addon).

1 Like