If I understand correctly you have 2 different repos with Laravel Sail and you want these 2 services to be in the same Docker network, right? If yes, then I tried to implement that few days ago and this is what I ended with.
Let's assume that we have 2 applications: one exposes REST API and second is consumer (client).
API:
docker-compose.yml
# For more information: https://laravel.com/docs/sail
version: '3'
services:
api.local:
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:
- my-network
depends_on:
- pgsql
- redis
pgsql:
image: 'postgres:13'
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
PGPASSWORD: '${DB_PASSWORD:-secret}'
POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
volumes:
- 'sailpgsql:/var/lib/postgresql/data'
networks:
- my-network
healthcheck:
test: ["CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}"]
retries: 3
timeout: 5s
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sailredis:/data'
networks:
- my-network
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- my-network
networks:
my-network:
name: my-network
driver: bridge
volumes:
sailpgsql:
driver: local
sailredis:
driver: local
.env
# add this line, it should be the same as your service name in docker-compose.yml
APP_SERVICE=api.local
Client:
docker-compose.yml
# For more information: https://laravel.com/docs/sail
version: '3'
services:
client.local:
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:
- proxy
networks:
proxy:
external:
name: my-network
.env
# add this line, it should be the same as your service name in docker-compose.yml
APP_SERVICE=client.local
And now the most important tip. You can't use http://localhost:3000 inside containers, because I assume that port 3000 is exposed outside containers. If you want to access API endpoint from client app you should call services by their names, e.g.
In client app
Route::get('/formulas', function() {
$endpoint = 'api.local' . '/api/formulas/all'; // api.local is going to be translated to appropriate URL by Docker, it's the same as service name in docker-compose.yml in API
return Http::withOptions([
'debug' => false,
])->get($endpoint);
});