Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Burano's avatar

Docker how to use service name in .env file?

I have 2 Docker containers spawned from 2 different docker-composer.yml files;

  • container-1 (Laradock container with Laravel app)
  • container-2 (container with rest api)

I linked them both in the same network, but in my Laravel .env inside container-1, if I try and reference a service inside container-2 as a host var (to send requests to the API), it doesn't work.

I checked with docker network inspect my_network and confirmed that container-1 and container-2 are both connected to it, but when I try and make requests the host env doesn't get swapped out so it just ends up calling <env>:443

Any docker experts here who can help me with solving this? Thanks!

0 likes
1 reply
bugsysha's avatar

Why aren't you using a single docker-compose.yml file?

Please or to participate in this conversation.