HTTP Task cannot call localhost
almen-wong opened this issue · comments
I use the emulator to create HTTP Task
The task is able to GET https://www.google.com, but when I GET http://localhost:8000 the task will fail
Response: UNKNOWN(2): HTTP status code -1
this is how I setup the emulator
docker-compose.yml
gcloud-tasks-emulator:
container_name: gcloud-tasks
image: ghcr.io/aertje/cloud-tasks-emulator:latest
command: -host 0.0.0.0 -port 8123 -queue "projects/mysandbox/locations/asia-east1/queues/test"
ports:
- "${TASKS_PORT:-8123}:8123"
and this is how i create the task
const client = new CloudTasksClient({
port: 8123,
servicePath: "localhost",
sslCreds: credentials.createInsecure(),
})
const parent = client.queuePath(
"mysandbox",
"asia-east1",
"test"
)
const task = {
httpRequest: {
httpMethod: "GET",
url: "http://localhost:8000",
}
}
const request = { parent, task }
await client.createTask(request)
any ideas why I cannot call the localhost? I can call http://localhost:8000 directly.
Hi @almen-wong,
You can either start the container's network in host mode if you're using linux (add network_mode: host
in the docker compose) or you can access the host on host.docker.internal
(instead of using localhost
).
A quick google of "call localhost from docker container" would've given you this useful SO answer.
Hope that helps, cheers.
Thanks for your help @aertje
However, when I changed to host.docker.internal
, i will have the error connection refused
seems like the host refuses to allow the docker container to connect
Do you know how to solve it?
Hope you resolved the issue @almen-wong. Closing this ticket as this is not a problem with the emulator.