How to Deploy a Container for Free: Step-by-Step Technical Guide
This hands-on guide walks you through deploying your first Docker container for free. We'll cover project setup, Dockerfile creation, environment configuration, and the actual deployment process with real code examples.
Prerequisites
- A GitHub account
- Basic familiarity with the command line
- A simple application (we'll use a Node.js example)
Step 1: Prepare Your Application
Let's create a simple Express.js application. Create these files in your project:
package.json
{
"name": "my-free-container",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.18.2"
}
}
index.js
const express = require('express');
const app = express();
const PORT = process.env.PORT || 3000;
app.get('/', (req, res) => {
res.json({
status: 'running',
message: 'Hello from my free container!',
timestamp: new Date().toISOString()
});
});
app.get('/health', (req, res) => {
res.status(200).send('OK');
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Step 2: Create a Dockerfile
Add a Dockerfile to your project root:
Dockerfile
# Use official Node.js LTS image
FROM node:20-alpine
# Set working directory
WORKDIR /app
# Copy package files first (for better caching)
COPY package*.json ./
# Install dependencies
RUN npm ci --only=production
# Copy application code
COPY . .
# Expose the port your app runs on
EXPOSE 3000
# Start the application
CMD ["npm", "start"]
Dockerfile Best Practices
- Use Alpine images — Smaller size means faster builds
- Copy package.json first — Enables Docker layer caching
- Use npm ci — Faster and more reliable than npm install
- Don't run as root — Add a non-root user for production
Step 3: Add a .dockerignore File
Create .dockerignore to exclude unnecessary files:
node_modules
npm-debug.log
.git
.gitignore
.env
*.md
.DS_Store
Step 4: Test Locally (Optional)
Before deploying, verify your container works locally:
# Build the image
docker build -t my-app .
# Run the container
docker run -p 3000:3000 my-app
# Test it
curl http://localhost:3000
Step 5: Push to GitHub
Initialize a git repository and push your code:
git init
git add .
git commit -m "Initial commit with Dockerfile"
git remote add origin https://github.com/yourusername/my-app.git
git push -u origin main
Step 6: Deploy to SnapDeploy
Now deploy your containerized application:
- Create account — Go to snapdeploy.dev and sign up (no credit card)
- New Container — Click "New Container" in the dashboard
- Connect GitHub — Authorize access and select your repository
- Configure — Set container name (becomes your-app.containers.snapdeploy.dev)
- Deploy — Click Deploy and watch the build logs
Step 7: Configure Environment Variables
If your app needs environment variables, add them in the dashboard:
# Example environment variables
NODE_ENV=production
DATABASE_URL=postgresql://user:pass@host:5432/db
API_KEY=your-secret-key
Access them in your code with process.env.VARIABLE_NAME.
Step 8: Verify Deployment
Once deployed, test your live container:
# Test the root endpoint
curl https://your-app.containers.snapdeploy.dev
# Expected response:
{
"status": "running",
"message": "Hello from my free container!",
"timestamp": "2026-01-06T10:30:00.000Z"
}
Troubleshooting Common Issues
Build fails with "npm ERR!"
Ensure package-lock.json is committed. Run npm install locally first.
Container starts but returns 502
Check that your app listens on the PORT environment variable, not a hardcoded port.
Container keeps restarting
Check the logs in the dashboard. Common cause: missing environment variables or database connection failures.
Next Steps
- Configure environment variables for secrets and config
- Add a custom domain to your container
- Set up monitoring to track container health
You now have a containerized application running for free. The free tier includes 100 hours of runtime—use the pause feature when not actively using your container to extend this further.
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.