You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-`hostname` - Your Worker's domain name (e.g., `'example.com'`). Required to construct preview URLs with wildcard subdomains like `https://8080-sandbox-abc123.example.com`. Cannot be a `.workers.dev` domain as it doesn't support wildcard DNS patterns.
31
+
-`name` - Friendly name for the port (optional)
31
32
32
33
**Returns**: `Promise<ExposePortResponse>` with `port`, `exposedAt` (preview URL), `name`
When using `wrangler dev`, you must add `EXPOSE` directives to your Dockerfile for each port. See [Expose Services guide](/sandbox/guides/expose-services/#local-development) for details.
When using `wrangler dev`, you must add `EXPOSE` directives to your Dockerfile for each port. See [Local development with ports](/sandbox/guides/expose-services/#local-development).
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/concepts/preview-urls.mdx
+24-12Lines changed: 24 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,20 +12,23 @@ Preview URLs work in local development without configuration. For production, yo
12
12
Preview URLs provide public HTTPS access to services running inside sandboxes. When you expose a port, you get a unique URL that proxies requests to your service.
Preview URLs support WebSocket connections. When a WebSocket upgrade request hits an exposed port, the routing layer automatically handles the connection handshake.
89
97
90
98
```typescript
99
+
// Extract hostname from request
100
+
const { hostname } =newURL(request.url);
101
+
91
102
// Start a WebSocket server
92
103
awaitsandbox.startProcess("bun run ws-server.ts 8080");
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/configuration/dockerfile.mdx
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,44 @@ Update `wrangler.jsonc` to reference your Dockerfile:
66
66
67
67
When you run `wrangler dev` or `wrangler deploy`, Wrangler automatically builds your Docker image and pushes it to Cloudflare's container registry. You don't need to manually build or publish images.
68
68
69
+
## Custom startup scripts
70
+
71
+
Run services automatically when the container starts by creating a custom startup script:
72
+
73
+
```dockerfile title="Dockerfile"
74
+
FROM docker.io/cloudflare/sandbox:0.3.3
75
+
76
+
COPY my-app.js /workspace/my-app.js
77
+
COPY startup.sh /workspace/startup.sh
78
+
RUN chmod +x /workspace/startup.sh
79
+
CMD ["/workspace/startup.sh"]
80
+
```
81
+
82
+
```bash title="startup.sh"
83
+
#!/bin/bash
84
+
85
+
# Start your services in the background
86
+
node /workspace/my-app.js &
87
+
88
+
# Must end with this command
89
+
exec bun /container-server/dist/index.js
90
+
```
91
+
92
+
Your startup script must end with `exec bun /container-server/dist/index.js` to start the SDK's control plane.
93
+
94
+
### Multiple services
95
+
96
+
```bash title="startup.sh"
97
+
#!/bin/bash
98
+
99
+
redis-server --daemonize yes
100
+
until redis-cli ping;do sleep 1;done
101
+
102
+
node /workspace/api-server.js &
103
+
104
+
exec bun /container-server/dist/index.js
105
+
```
106
+
69
107
## Related resources
70
108
71
109
-[Image Management](/containers/platform-details/image-management/) - Building and pushing images to Cloudflare\'s registry
0 commit comments