← All Tutorials
DevOpsFeb 5, 202610 min read

Deploy Docker Containers on Rackline

Build, push, and deploy Docker containers with the Rackline container registry and docker-compose.

Introduction

Containers provide consistent, reproducible deployments across environments. Rackline includes a private container registry, native Docker support on all droplets, and orchestration for multi-container applications via docker-compose. This tutorial covers the full container lifecycle from Dockerfile to production deployment.

Prerequisites

  • A Rackline account with a droplet (2 GB RAM minimum)
  • Docker Desktop installed locally
  • Basic familiarity with Docker concepts

Step 1 — Write an Optimized Dockerfile

A well-structured Dockerfile uses multi-stage builds to minimize image size and layer caching to speed up rebuilds. Separate dependency installation from application code so dependencies are only rebuilt when package files change.

dockerfile
# Dockerfile
FROM node:22-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --production

FROM node:22-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:22-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN addgroup --system --gid 1001 appgroup
RUN adduser --system --uid 1001 appuser
COPY --from=deps /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
USER appuser
EXPOSE 3000
CMD ["node", "dist/server.js"]

Pro Tip

Always run containers as a non-root user. The USER directive in the Dockerfile prevents privilege escalation attacks if your container is compromised.

Step 2 — Push to Rackline Container Registry

Rackline provides a private container registry included with every account. Images stored in the registry are automatically available to all your droplets in the same region with no additional network transfer costs.

bash
# Log in to the Rackline registry
rackline registry login

# Build and tag your image
docker build -t registry.rackline.net/myapp:1.0.0 .
docker tag registry.rackline.net/myapp:1.0.0 registry.rackline.net/myapp:latest

# Push to registry
docker push registry.rackline.net/myapp:1.0.0
docker push registry.rackline.net/myapp:latest

# List images in your registry
rackline registry images list

Step 3 — Deploy a Single Container

Deploy your container image to a Rackline droplet. Rackline pulls the image, configures networking, sets up health checks, and manages container lifecycle including automatic restarts on failure.

bash
# Deploy a container
rackline deploy \
  --image registry.rackline.net/myapp:1.0.0 \
  --port 3000 \
  --health-check /health \
  --health-interval 30s \
  --restart-policy always \
  --memory 512m \
  --cpus 1

# View running containers
rackline containers list

# View container logs
rackline containers logs myapp --follow

Step 4 — Deploy Multi-Container Apps with Compose

For applications with multiple services (web server, database, cache, worker), use a docker-compose file. Rackline supports docker-compose v3 syntax and handles inter-container networking automatically.

yaml
# docker-compose.yml
services:
  web:
    image: registry.rackline.net/myapp:latest
    ports:
      - "3000:3000"
    environment:
      - DATABASE_URL=postgresql://postgres:secret@db:5432/mydb
      - REDIS_URL=redis://cache:6379
    depends_on:
      - db
      - cache

  db:
    image: postgres:17-alpine
    volumes:
      - pgdata:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=mydb

  cache:
    image: redis:7.4-alpine
    volumes:
      - redisdata:/data

volumes:
  pgdata:
  redisdata:

Step 5 — Deploy Compose to Rackline

Push your docker-compose configuration to Rackline. The platform provisions the necessary resources, sets up internal networking between containers, and configures external access for the web service.

bash
# Deploy the full stack
rackline deploy --compose docker-compose.yml \
  --environment production

# Scale a specific service
rackline containers scale web --replicas 3

# Update a single service
rackline deploy --compose docker-compose.yml \
  --service web \
  --image registry.rackline.net/myapp:1.1.0

Pro Tip

Use named volumes for persistent data. Unnamed volumes are ephemeral and will be lost when containers are recreated during deployments.

Conclusion

You are now deploying Docker containers on Rackline with a private registry, health checks, and multi-container orchestration. Containers provide the consistency and portability needed for modern application deployments. For scaling beyond a single host, see the Scaling Your Infrastructure tutorial.