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 upcommand. No additional configuration required: just launch 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).
- Take advantage of high performance and enhanced security on private, dedicated infrastructure.
- Apply updates with a single click for simple, effortless maintenance.
Your containers can be running in production in about five minutes. Stackhero manages the infrastructure, updates, and security for you, so you can focus on developing your applications. Learn 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.
Prepare your first deploy to production
Before deploying your app to production, you need to prepare a few configuration files:
- Copy
secrets/global.production.exampletosecrets/global.production. - Edit
secrets/global.productionand replace<XXXXXX>.stackhero-network.comwith your Docker service hostname from your Stackhero dashboard. - Copy
secrets/my-app.production.exampletosecrets/my-app.production. - Edit
secrets/my-app.productionand insert your credentials. - Update
docker/docker-compose.production.ymlby replacing<XXXXXX>.stackhero-network.comwith your Docker service hostname.
Deploy to production
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.
Display 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-DDwith the desired date), run:make production-logs | grep "YYYY-MM-DD"
Customize domain names
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 customize your domain names:
-
To serve
api.my-company.comvia your containermy-appon port 5000 with TLS encryption, update thedocker/docker-compose.production.ymlfile by replacing thelabelssection 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.comvia your containermy-appon port 5000 and redirect all requests fromwww.my-company.comtomy-company.com, update thelabelssection 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.comandwww.my-company.comso that each points as a CNAME to your Docker service athttps://<XXXXXX>.stackhero-network.com.