Need Two docker containers to communicate together.
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I've created a Docker/docker-compose script for my php Laravel app.

You can find it here:******

See the docker-compose.yml file here *****

Basically, I have these settings in my .env file:


if I copy the folder and change the variables above to :


Both apps work at http://docker.test/ and http://docker-two.test:8001/

But if I uncomment these lines in docker-two (in my route file web.php):

$response = Http::withHeaders([
return $response;

Then I can see that the docker-two app isn't able to communicate with the first app. I get this error:

cURL error 7: Failed to connect to docker.test port 80: Connection refused (see

I'll pay extra someone finds a solution.

frow what i know, you have to run them in the same network in order to make them connect with each others.
Chlegou 7 months ago
They are in the same network but have different container names.
randomhelprequested 7 months ago
do you mean different docker instances? because you can't have 2 docker containers in the same docker instance with the same name.
Chlegou 7 months ago
I have dockerapp and docker-twoapp, dockerwebserver and docker-twowebserver and dockerdb and docker-twodb. So the containers have different names.
randomhelprequested 7 months ago
the utility of docker is running multiple containers in the same dockerapp (same server). why you don't run all the containers in the same docker app?
Chlegou 7 months ago
I guess that means I'd need to have just one docker-compose.yml file ? Is that what you mean ?
randomhelprequested 7 months ago
If you're willing to help, we could meet on a slack team. Let me know !!! As long as I can find a way to have multiple websites running and able to communicate with each other on my local machine. One Dockerfile or not I'll be happy. Let me know.
randomhelprequested 7 months ago
i have struggled with this 2 weeks ago :p i would be happy to share the knowledge i have got to help you out. but let me tell you first that i'm a basic learner of docker. this is my email for further contact, we could schedule a Hangout call:
Chlegou 7 months ago
Would you check the solution? Building dockers takes much time, but ypu can believe it's working - I checked it.
TheOsch 7 months ago

Crowdsource coding tasks.

1 Solution

That's where the problem is: the second docker doesn't know the docker.test host. The simplest possible solution is to edit docker-compose.yml:

  1. Change

    container_name: ${DOCKER_CONTAINER_NAME_SLUG}_webserver


    container_name: ${DOCKER_CONTAINER_NAME_SLUG}.test

  2. Add one line to networks section in BOTH directories and another line only in THE SECOND one, So that the whole section will look like this:

    #Docker Networks
    ....external: true #This only in the second one docker_test_network
    ....driver: bridge
    (sorry, I replaced spaces with dots, couldn't make Bountify editor keep indents).

  3. Uncomment those lines in the web.php of the second server, run the first server then the second one. Will work.

What does it do: it creates a network common for both containers; each service using this network can communicate to other service using the service's name as a hostname, no matter in what container(s) are both services situated.