Hi @s.lavoie.b@gmail.com
I am not a Docker expert but I know that if you want to communicate between 2 docker containers they need to be on the same network. Maybe this post will help you? https://stackoverflow.com/a/38089080
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am currently porting my apps from Homestead to Docker (via Laravel Sail) since I upgraded to a m1 mac. Everything works as it used to with Homestead except one thing.
Basically I have two apps and I want them to talk with Laravel's HTTP client (ultimately Guzzle behind the scenes).
On homestead, they both had a .test url and communicated with it. So app1.test called app2.test without issues.
On docker, I understand that these kinds of url cannot work and I have to use ports instead. Fine, now App1 has port 3999 and App2 4000.
So if I use curl localhost:3999 in my terminal, it works and I get the right response. The mac app Insomnia gives me the right response too.
But when App2 tries Http::get("http://localhost:3999"). I get this error:
cURL error 7: Failed to connect to localhost port 3999: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:3999
And if I try Http::get("https://google.com") everything is fine. So that's not an issue with the package.
I don't know much about docker, so am I misunderstanding something here? Is there some local network or HTTP thing that I don't understand? I saw in some places online I might need to use an "external" network in my docker_compose.yml? But I'm not sure this applies here.
My docker setup is similar (in both files) to what is provided in the documentation (see below). I just specified the ports mentioned previously in my .env file.
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- '.:/data'
networks:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sailmysql:/var/lib/mysql'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
Please or to participate in this conversation.