Guide

Branch Deployments: How to Create Staging and Preview Environments with Docker Containers

SnapDeploy Team 2026-03-20 9 min read
preview environment dockerbranch deploymentsstaging environment containerpreview environmentsdocker stagingmulti-container deployment

Every development team eventually faces the same problem: you need to test changes before they hit production, but spinning up isolated environments is painful. Preview environments — temporary deployments tied to specific branches — solve this by letting team members review features in a live setting before merging.

If you work with Docker containers, you already know the challenge. Platforms like Vercel and Netlify offer one-click preview deployments, but only for their supported frameworks. When your application runs in Docker, your options narrow considerably.

Important note: This guide describes a manual multi-container branching strategy. SnapDeploy does not automatically spin up containers when you open a pull request. Instead, you manually create containers per branch and let auto-deploy handle updates on push. The workflow is practical but requires manual setup and cleanup.

For small teams running Docker workloads who need a straightforward way to maintain staging and preview environments, this approach is practical and affordable. Let's walk through how it works.

What Are Branch Deployments?

Branch deployments are isolated environments that run code from a specific Git branch. Instead of deploying only your main branch to a single server, you deploy multiple branches simultaneously, each with its own URL.

The concept is straightforward. Your main branch deploys to production. Your develop branch deploys to a staging URL. A feature branch like feature/new-checkout deploys to its own preview URL. Each deployment runs independently.

This pattern gives teams several advantages:

  • Code review becomes visual. Reviewers can click a link and see the feature running, not just read the diff.
  • QA can test in parallel. Multiple features can be tested simultaneously without waiting for a shared staging server.
  • Integration issues surface early. Running the full application catches environment-specific bugs before production.
  • Stakeholder feedback improves. Product managers and designers can interact with features before they ship.

Manual Branch Deployment Strategy with SnapDeploy

SnapDeploy lets you connect a GitHub repository to a container and configure it to auto-deploy when code is pushed to a specific branch. The key detail: you can create multiple containers that all point to the same repository but track different branches. This is the foundation of a manual branch deployment strategy.

Step 1: Deploy Your Production Container

  1. Create a new container on SnapDeploy and choose a clear name like myapp-prod.
  2. Connect your GitHub repository.
  3. Select the main branch as the deployment branch.
  4. Enable auto-deploy so that every push to main triggers a new build.
  5. Configure your production environment variables.

Step 2: Create a Staging Container

  1. Create another container named myapp-staging.
  2. Connect the same GitHub repository.
  3. Select the develop branch.
  4. Enable auto-deploy for this branch.
  5. Set staging-specific environment variables (different database, debug flags, etc.).

Now every push to develop automatically redeploys your staging container. No additional steps required.

Step 3: Create Feature Branch Containers

When a developer starts work on a feature that needs a live preview:

  1. Create a new container named something like myapp-feature-checkout.
  2. Connect the same GitHub repository.
  3. Select the feature branch, such as feature/new-checkout.
  4. Enable auto-deploy. Commits pushed to the branch trigger automatic rebuilds.
  5. Share the container URL with reviewers.

Step 4: Clean Up After Merge

Once the feature branch is merged and the pull request is closed, manually delete the preview container from the SnapDeploy dashboard. There is no automatic cleanup — this is your responsibility.

URL Structure and Naming Conventions

Every container on SnapDeploy gets a unique subdomain based on the container name:

containername.containers.snapdeploy.dev

This means your naming convention directly determines your preview URLs. With consistent naming, your team can predict URLs without looking them up:

Container Name URL
myapp-prodmyapp-prod.containers.snapdeploy.dev
myapp-stagingmyapp-staging.containers.snapdeploy.dev
myapp-feature-checkoutmyapp-feature-checkout.containers.snapdeploy.dev
myapp-feature-authmyapp-feature-auth.containers.snapdeploy.dev

A good naming convention: {project}-{environment-or-branch}. Keep names lowercase with hyphens. This predictable URL structure makes it easy to add preview links to your PR descriptions.

Environment Variables per Branch

One of the advantages of running separate containers per branch is that each container has its own environment variables. This is essential for staging environment container configurations where preview environments need to behave differently from production.

  • Database connections. Staging and preview containers should point to a separate database.
  • API keys. Use sandbox or test API keys for third-party services.
  • Feature flags. Enable experimental features in preview environments.
  • Debug settings. Turn on verbose logging in non-production containers.
  • Application URLs. If your app generates absolute URLs, each environment needs its own base URL.

On SnapDeploy, environment variables are configured per container through the dashboard. Changes to one container's environment do not affect any other container, even if they share the same repository.

Database Strategy for Branch Deployments

Preview environments need data to be useful. A checkout feature preview is meaningless if the database is empty. Common approaches:

  • Shared staging database. All preview containers connect to the same staging database. Simple, but concurrent branches can interfere with each other.
  • Per-branch databases. Each preview container gets its own database instance. Complete isolation but adds cost.
  • Read-only production replica. Preview containers connect to a read-only copy of production data. Realistic data without corruption risk.
  • Seed data scripts. Maintain a script that populates a fresh database with test data. Works well with embedded databases.

For most small teams, a shared staging database is sufficient. Just coordinate migrations carefully when multiple branches change the schema simultaneously.

Resource and Cost Considerations

Running multiple containers for branch deployments consumes resources. SnapDeploy's pricing plans limit the number of containers you can create:

Plan Container Limit Starting Price
Free2 containers$0/month
Hobby2 containers$9/month
Starter3 containers$39/month
Pro8 containers$69/month

On the Free or Hobby plan, you realistically have room for one production container and one preview. The Starter plan gives you production, staging, and one preview. The Pro plan with 8 containers offers flexibility for teams running multiple feature previews. On the Hobby plan, idle containers auto-sleep — useful for previews that don't consume resources when nobody is reviewing them. Delete preview containers promptly after branches merge to free up slots.

Cleaning Up Preview Environments

Since SnapDeploy does not automatically remove containers when branches are merged, cleanup is your responsibility. Build it into your workflow:

  1. After merging a PR, delete the corresponding preview container from the dashboard.
  2. Weekly audits. Designate someone to check for containers tied to branches that no longer exist.
  3. Naming conventions help. Cross-reference container names with your repository's active branches to identify stale deployments.

This manual overhead is the main trade-off. It's manageable for small teams with a few active branches, but becomes tedious with many parallel features.

Comparison with Automated Preview Platforms

It's worth being direct about how this manual approach compares to platforms with built-in PR preview environment deployments.

Automated Preview Platforms (Vercel, Netlify)

Vercel and Netlify are the gold standard for automated preview environments. When you open a pull request, they automatically build and deploy your branch, post the preview URL as a PR comment, and tear down the environment when the PR closes. It's seamless. However, these platforms are designed for specific ecosystems:

  • Vercel focuses on Next.js and frontend frameworks. Python APIs, Go services, or Java monoliths aren't supported.
  • Netlify targets static sites and serverless functions. Full Docker container support isn't part of their model.

SnapDeploy's Manual Approach

Less convenient but more flexible in one specific way: it runs any Dockerized application. If your project has a Dockerfile, it works. The trade-offs are clear:

Feature Vercel/Netlify SnapDeploy
Auto-create on PR openYesNo (manual)
Auto-destroy on PR closeYesNo (manual)
PR comment with URLYesNo
Docker container supportLimited/NoneYes
Framework restrictionsYesNone (any Dockerfile)
Auto-deploy on pushYesYes
Independent env varsYesYes

If your stack fits within Vercel or Netlify's supported frameworks and you value automation, those platforms are the better choice. If you need preview environment docker support for applications that require specific system dependencies or use unsupported languages, the manual approach described here fills the gap.

When This Approach Works and When It Doesn't

Works Well When:

  • Your team is small (2–5 developers) with 1–3 active feature branches at a time.
  • You need full Docker support for applications that don't fit PaaS frameworks.
  • Preview frequency is low. Major features benefit from visual review, not every PR.
  • You want affordable staging. A permanent staging container alongside production is cheap.

Does Not Work Well When:

  • Your team is large with many simultaneous feature branches. Container limits and manual overhead become unworkable.
  • You want full automation. If creating and destroying environments per PR is a hard requirement, use Vercel, Netlify, or a custom CI/CD pipeline.
  • Your application requires multiple services. Needing a web server, worker, and database per deployment exhausts container limits quickly.
  • Compliance requires environment parity guarantees. Manual processes introduce human error.

Conclusion

Preview environments improve code review and catch bugs before production. While SnapDeploy doesn't offer automated PR preview deployments, its GitHub integration and multi-container support provide a practical manual workflow for teams that need Docker-based staging environment container deployments.

The approach is straightforward: create a container per branch, let auto-deploy handle updates on push, and clean up containers when branches merge. If this fits your workflow, get started with SnapDeploy and try setting up a staging container alongside your production deployment.

Ready to Deploy?

Get 100 free hours to deploy and test your applications. No credit card required.

Get DevOps Tips & Updates

Container deployment guides, platform updates, and DevOps best practices. No spam.

Unsubscribe anytime. We respect your privacy.

More Articles