This tutorial explains how to build and push Docker images inside a Blaxel sandbox. It also explains how to run Docker containers and expose them securely using sandbox preview URLs.Documentation Index
Fetch the complete documentation index at: https://docs.blaxel.ai/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
- Blaxel CLI installed and authenticated (
bl login) - Node.js 18+ or Python 3.12+ installed
- Blaxel SDK installed in your project (
npm install @blaxel/coreorpip install blaxel)
Create and connect to a sandbox
Blaxel provides a ready-to-use sandbox image (blaxel/docker-in-sandbox) with everything you need to build and run Docker images. This image also includes the Docker CLI, Docker Compose and iptables-legacy (as a replacement for nftables).
Create and deploy a sandbox using the Docker sandbox image:
Run a Docker container
You can run a container from any public image. Here is an example of running an NGINX container:Open a shell into a running Docker container
Usedocker exec to open a shell inside the running container:
Expose a Docker container at a sandbox preview URL
Once a Docker container is running inside your sandbox, you can expose it externally via a preview URL. To see this in action, run an NGINX container on sandbox port 8081:Build and push a Docker image
You can also build and push images from the sandbox. To see this in action, first create a minimalDockerfile in the sandbox’s /app directory:
If you plan to run the final image on a Blaxel sandbox, add the
--platform linux/amd64 flag when building so the image runs correctly.docker run:
Use Docker Compose
The Docker sandbox image includes a sample Docker Compose application in theexample directory. Try it with the following commands:
Ensure that your sandbox is configured with sufficient memory for the build process and output.
