Docker: Production platform

This documentation is part of the Node.js guide. You can view the complete guide here: How to use and deploy a Node.js app with Docker.

Welcome to the Stackhero documentation

Stackhero offers a ready-to-use Docker cloud CaaS (Containers as a Service) platform, designed for fast and reliable container deployments:

  • Deploy to production with a single docker-compose up command. No additional configuration is required: simply start your containers.
  • Choose your own domain name, automatically secured with HTTPS (for example: https://api.your-company.com, https://www.your-company.com, or https://backoffice.your-company.com).
  • Benefit from high performance and enhanced security on private, dedicated infrastructure.
  • Apply updates with a single click for straightforward, effortless maintenance.

Your containers can be live in production in around five minutes. Stackhero manages the infrastructure, updates, and security for you, so you can focus on developing your applications. Find out more about Docker CaaS cloud hosting.

If you do not yet have a Stackhero for Docker service, you can create one easily from your Stackhero dashboard. It will be activated within approximately 2 minutes.

If you are new to Stackhero, you can try the Docker container cloud hosting free for a month.

Before deploying your app to production, you need to prepare a few configuration files:

  1. Copy secrets/global.production.example to secrets/global.production.
  2. Edit secrets/global.production and replace <XXXXXX>.stackhero-network.com with your Docker service hostname from your Stackhero dashboard.
  3. Copy secrets/my-app.production.example to secrets/my-app.production.
  4. Edit secrets/my-app.production and insert your credentials.
  5. Update docker/docker-compose.production.yml by replacing <XXXXXX>.stackhero-network.com with your Docker service hostname.

Deploying to production is straightforward: run:

make production-deploy

This command creates a Docker container, transfers your project data, and sends it to your Docker service in production. Open your browser and navigate to your Docker service hostname (for example, https://<XXXXXX>.stackhero-network.com). You should see your REST API reply "Hello World".

You can also use make production, which deploys your containers and displays real-time logs.

To monitor your production environment or troubleshoot issues, you can view your logs using these commands:

  • To stream live logs, run: make production-logs-live
  • To retrieve all stored logs, run: make production-logs
  • To retrieve logs for a specific day (replace YYYY-MM-DD with the desired date), run: make production-logs | grep "YYYY-MM-DD"

If you wish to use a different domain name instead of https://<XXXXXX>.stackhero-network.com, Stackhero for Docker integrates Traefik to simplify domain management. Traefik handles HTTP routing and TLS encryption (HTTPS) for you.

Here are a couple of examples to customise your domain names:

  • To serve api.my-company.com via your container my-app on port 5000 with TLS encryption, update the docker/docker-compose.production.yml file by replacing the labels section with:

        labels:
          - "traefik.enable=true" # Enable Traefik to route traffic to this container
          - "traefik.http.routers.my-app.rule=Host(`api.my-company.com`)" # Define the host
          - "traefik.http.routers.my-app.tls.certresolver=letsencrypt" # Use letsencrypt for TLS certificates
          - "traefik.http.services.my-app.loadbalancer.server.port=5000" # Specify port 5000
    
  • To serve my-company.com via your container my-app on port 5000 and redirect all requests from www.my-company.com to my-company.com, update the labels section in the same file with:

        labels:
          - "traefik.enable=true"
          - "traefik.http.routers.my-app.rule=Host(`my-company.com`) || Host(`www.my-company.com`)" # Include both domains
          - "traefik.http.routers.my-app.tls.certresolver=letsencrypt"
          - "traefik.http.services.my-app.loadbalancer.server.port=5000" # Specify port 5000
    
          # Redirect www.my-company.com to my-company.com:
          - "traefik.http.routers.my-app.middlewares=redirect-www"
          - "traefik.http.middlewares.redirect-www.redirectregex.regex=^https://www.my-company.com/(.*)"
          - "traefik.http.middlewares.redirect-www.redirectregex.replacement=https://my-company.com/$${1}"
          - "traefik.http.middlewares.redirect-www.redirectregex.permanent=true"
    

Do not forget to configure the DNS for my-company.com and www.my-company.com so that each points as a CNAME to your Docker service at https://<XXXXXX>.stackhero-network.com.