Deploy to Snowpark Container Services (SPCS)
Deploy any containerized application to Snowflake using Snowpark Container Services. Works with any Docker-based app (Next.js, Python, Go, etc.).
When to Use
- User has a containerized app (Docker) ready to deploy
- User wants to host an app on Snowflake infrastructure
- User mentions SPCS, Snowpark Container Services, or deploying to Snowflake
Tools Used
bash- Run docker commands, snow CLIsnowflake_sql_execute- Create compute pools, repos, servicescortex browser- Verify deployed apps
Stopping Points
- ⚠️ Step 1: Confirm app builds successfully
- ⚠️ Step 2: Confirm SPCS prerequisites exist
- ⚠️ Step 5: Confirm deployment success
- ⚠️ Step 6: Confirm consumer role access
Workflow
Step 1: Verify App Readiness
Goal: Ensure the app is containerized and builds correctly.
Actions:
- Confirm app has a working
Dockerfile - Confirm app builds locally:
docker build --platform linux/amd64 -t <image-name>:latest . - Confirm app exposes a port (default: 8080)
Output: Successful local Docker build.
⚠️ MANDATORY STOPPING POINT: Do NOT proceed until app builds successfully.
Step 2: Verify SPCS Prerequisites
Goal: Ensure compute pool and image repository exist.
Actions:
Check current role:
SELECT CURRENT_ROLE(), CURRENT_USER();Check/create compute pool:
SHOW COMPUTE POOLS; -- If no accessible pool exists: CREATE COMPUTE POOL <pool_name> MIN_NODES = 1 MAX_NODES = 1 INSTANCE_FAMILY = CPU_X64_XS;Check/create image repository:
SHOW IMAGE REPOSITORIES; -- If needed: CREATE IMAGE REPOSITORY <db>.<schema>.<repo_name>;Login to registry:
snow spcs image-registry login --connection <conn>
Output: Compute pool and image repository ready.
⚠️ MANDATORY STOPPING POINT: Do NOT proceed until prerequisites exist.
Step 3: Create Service Specification
Goal: Define the service configuration.
Actions:
Create
service-spec.yamlwith the following template:spec: containers: - name: <app-name> image: /<db>/<schema>/<repo>/<image>:latest env: HOSTNAME: "0.0.0.0" PORT: "8080" NODE_ENV: production resources: requests: memory: 1Gi cpu: 500m limits: memory: 2Gi cpu: 1000m readinessProbe: port: 8080 path: / endpoints: - name: <endpoint-name> port: 8080 public: trueAdjust
resources,port, andenvbased on app requirements.
Output: service-spec.yaml file ready for deployment.
Next: Proceed to Step 4.
Step 4: Build and Push Image
Goal: Push the container image to Snowflake registry.
Actions:
Build, tag, and push:
docker build --platform linux/amd64 -t <image-name>:latest . docker tag <image-name>:latest <registry-url>/<db>/<schema>/<repo>/<image-name>:latest docker push <registry-url>/<db>/<schema>/<repo>/<image-name>:latestRegistry URL format:
<account>.registry.snowflakecomputing.com
Output: Image pushed to Snowflake image repository.
Next: Proceed to Step 5.
Step 5: Deploy Service
Goal: Create the SPCS service and verify it's running.
Actions:
Create the service:
CREATE SERVICE <service_name> IN COMPUTE POOL <pool_name> FROM SPECIFICATION $$ <contents of service-spec.yaml> $$ MIN_INSTANCES = 1 MAX_INSTANCES = 1;Monitor status and get URL:
SELECT SYSTEM$GET_SERVICE_STATUS('<service_name>'); SHOW ENDPOINTS IN SERVICE <service_name>;Extract
ingress_urlfrom SHOW ENDPOINTS and display to user.Verify deployment:
cortex browser open "https://<ingress_url>" cortex browser snapshot -i
Output: Service running with accessible URL.
⚠️ MANDATORY STOPPING POINT: Do NOT proceed until user confirms deployment success.
Step 6: Grant Consumer Access
Goal: Configure access for the consuming role.
Actions:
Ask user: "What role will consume this service?"
Check the grants to the role
SHOW GRANTS TO ROLE <consumer_role>;Grant ALL THREE of the following (all are required, do not skip any):
-- 1. Database access (REQUIRED) GRANT USAGE ON DATABASE <db> TO ROLE <consumer_role>; -- 2. Schema access (REQUIRED) GRANT USAGE ON SCHEMA <db>.<schema> TO ROLE <consumer_role>; -- 3. Service endpoint access (REQUIRED) — note: GRANT SERVICE ROLE, not GRANT USAGE ON SERVICE GRANT SERVICE ROLE <service_name>!ALL_ENDPOINTS_USAGE TO ROLE <consumer_role>;If the service is using a table in Snowflake, grant what the service needs:
GRANT USAGE ON DATABASE <table_db> TO ROLE <consumer_role>; GRANT USAGE ON SCHEMA <table_db>.<table_schema> TO ROLE <consumer_role>; -- Grant privileges the service requires (SELECT, INSERT, UPDATE, DELETE, etc.) GRANT <privileges> ON TABLE <table_db>.<table_schema>.<table> TO ROLE <consumer_role>;
Output: Consumer role can access the service.
⚠️ MANDATORY STOPPING POINT: Do NOT proceed until user confirms consumer role access works.
Updating a Service
⚠️ CAUTION: Always use ALTER SERVICE to update. Never drop and recreate—this changes the URL and breaks integrations.
docker build --platform linux/amd64 -t <image-name>:latest .
docker tag <image-name>:latest <registry-url>/<db>/<schema>/<repo>/<image-name>:latest
docker push <registry-url>/<db>/<schema>/<repo>/<image-name>:latest
ALTER SERVICE <service_name> FROM SPECIFICATION $$
<full yaml spec>
$$;
Troubleshooting
Get service logs:
SELECT SYSTEM$GET_SERVICE_LOGS('<service_name>', 0, '<container_name>');
Common issues:
| Problem | Cause | Fix |
|---|---|---|
| Image not found | Path mismatch | Use exact format: /<db>/<schema>/<repo>/<image>:latest (case-sensitive, leading slash required) |
| Service fails readiness | Port mismatch | Align three ports: readinessProbe.port, PORT env var, endpoints.port |
| Auth errors on push | Expired login | Re-run snow spcs image-registry login --connection <conn> |
| Permission errors | Missing grants | Grant required privileges to the service owner role |
Output
- Deployed SPCS service URL
- Service status confirmation
- Consumer role access configured