Hi,
I’m trying to use cloudflare tunnel to visit my docker container in my desktop. It’s a pretty sample demo to test if it’s workable. I just set up a cloudflare/cloudflared tunnel with docker network “backend”, and set up a express container to connnet with that network. The backend express can be accessed by http://localhost:3000
. The problem is when I set url to be “express_container:3000” and try to visit my express backend through tunnel, I got error like "ERR Request failed error=“Unable to reach the origin service. The service may be down or it may not be responding to traffic from cloudflared”. It should be workable, since I’m successful when I set url to be “host.docker.internal:3000” in my host name configuration page. I also try it with “localhost:3000” and it doesn’t work.
So it seems like I miss something in url setting since it worked with “host.docker.internal:3000”. But I’m not sure what I missed.
Here is more details about the code.
Tunnel docker-compose.file:
version: ‘3.9’
networks:
frontend:
backend:
services:
cloudflaretunnel:
container_name: service-demo-cloudflaretunnel
image: cloudflare/cloudflared:latest
restart: unless-stopped
environment:
- TUNNEL_TOKEN=${TUNNEL_TOKEN}
command: tunnel --no-autoupdate run
networks:
- frontend
- backend
express docker compose file:
version: ‘3’
services:
express:
image: node:latest
working_dir: /express
volumes:
- .:/express:rw
command: sh -c ‘npm install nodemon && npm install && npm install @babel/core @babel/cli @babel/preset-env @babel/node && npm start’
ports:
- 3000:3000
container_name: express_container
networks:
- mydevice2external_backend
networks:
mydevice2external_backend:
external: true
My docker network is:
[
{
“Name”: “mydevice2external_backend”,
“Id”: “9f7346d1b567891414ca9678f2e1e371bd76696f9c8d428d4b88a075e3ed3cf2”,
“Created”: “2023-07-14T19:44:37.750180156Z”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: [
{
“Subnet”: “172.19.0.0/16”,
“Gateway”: “172.19.0.1”
}
]
},
“Internal”: false,
“Attachable”: false,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“Containers”: {
“60e523c33c449ddeb5e9b18460ac327ea87dfb07e4bc9c55a2ef0b992d7c3f13”: {
“Name”: “express_container”,
“EndpointID”: “b28451206c24c0ea179954f583e032042eee8009089e9fa084c1758e19cf7432”, 19cf7432",
“MacAddress”: “02:42:ac:13:00:02”,
“IPv4Address”: “172.19.0.2/16”,
“IPv6Address”: “”
}
},
“Options”: {},
“Labels”: {
“com.docker.compose.network”: “backend”,
“com.docker.compose.project”: “mydevice2external”,
“com.docker.compose.version”: “2.19.1”
}
}
]
I would like to use something like “express_container:3000” to access my express backend.
Any idea about this? Thank you!