- docker
- devops
- vps
- https
Put your project on your own server in 20 minutes: Docker, automatic HTTPS and a deploy on every push
Deploying a backend project to a VPS with Docker, setting up automatic HTTPS with Caddy and letting GitHub Actions update the server on every git push. Step by step, with working files.
You have a project that runs on your local machine. Now it has to go on the internet: on your own domain, with HTTPS, and set up so that the server updates itself after every git push. No logging into the server to copy files by hand, no restarting processes, no "it worked on my machine" conversations.
In this post we build exactly that setup. By the end you will have:
- the application running in a Docker container;
- the domain opening over HTTPS, with the certificate renewed automatically;
- GitHub Actions updating the server after every push to the
mainbranch.
The example uses Node.js, but the setup is the same for Python, Go, PHP or any other backend: only the Dockerfile changes.
The setup
git push → GitHub Actions → SSH to the server → git pull + docker compose up
│
internet → https://api.example.com → Caddy (HTTPS) → app containerWhat you need
- VPS: 1 vCPU and 1-2 GB RAM are enough for a small API. Ubuntu 24.04.
- A domain (or subdomain), for example
api.example.com. - A GitHub repository with your project.
- Access to the server with an SSH key.
Step 1: prepare the server
Log into the server and update the system:
sudo apt update && sudo apt -y upgradeInstall Docker with the official script and add your user to the docker group:
curl -fsSL https://get.docker.com | sudo sh
sudo usermod -aG docker $USERLog out of the server and back in for the group change to take effect. Check:
docker run --rm hello-worldCreate a directory for the project and clone the repository:
sudo mkdir -p /opt/app && sudo chown $USER /opt/app
git clone https://github.com/user/project.git /opt/appIf the repository is private, create a separate "deploy key" on the server and add it to the repository on GitHub with read-only access.
Step 2: put the application in a container
A Dockerfile in the project root:
FROM node:22-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
ENV NODE_ENV=production
EXPOSE 3000
USER node
CMD ["node", "server.js"]Three small but important details:
package*.jsonis copied first: when the code changes, the dependencies are not downloaded again, and the build gets several times faster.npm ci --omit=dev: production dependencies only, with exact versions.USER node: the container does not run as root.
Don't forget the .dockerignore file either, or node_modules and .env end up in the image:
node_modules
.git
.envStep 3: automatic HTTPS with Caddy
Caddy is a web server, and its nicest feature is this: you write the domain, and it gets a certificate from Let's Encrypt by itself and renews it on time. No separate certbot and cron needed.
Caddyfile:
api.example.com {
reverse_proxy app:3000
}docker-compose.yml:
services:
app:
build: .
restart: unless-stopped
env_file: .env
caddy:
image: caddy:2
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
volumes:
caddy_data:The application port (3000) is not exposed to the outside; only Caddy reaches it, over the internal network. The certificates are kept in the caddy_data volume so they are not requested again on every restart.
The domain's DNS must have an A record pointing to the server's IP, and ports 80 and 443 must be open. Then:
cd /opt/app
nano .env # DATABASE_URL, API keys, etc.
docker compose up -d --buildA minute later https://api.example.com should open with the green padlock.
A shorter way at JezaHost: without Caddy. The portal has a Domains & SSL → Add domain section. In your domain's DNS, point theArecord to95.86.162.6(for a subdomain, theCNAMErecord totenant-web.jezacloud.com), pick your server from the list and enter the application's port (3000in this example). The SSL certificate is issued automatically and renews itself. In that case remove thecaddyservice fromdocker-compose.ymland addports: ["3000:3000"]to the application. If you use Cloudflare, make the cloud grey ("DNS only") for the domain. Details: Domains & SSL.
Step 4: automatic deploy on every push
Now the most interesting part. After every push to the main branch, GitHub Actions will log into the server over SSH, pull the new code and rebuild the container.
4.1. A separate key for deploys. Don't give your personal key to GitHub. Create a new key on your computer:
ssh-keygen -t ed25519 -f deploy_key -N "" -C "github-actions"Add the contents of deploy_key.pub to the ~/.ssh/authorized_keys file on the server.
4.2. Secrets on GitHub. In the repository, add them under Settings → Secrets and variables → Actions:
SSH_HOST: the server's address;SSH_USER: the user name;SSH_KEY: the full contents of thedeploy_keyfile (the private key).
4.3. The workflow. In the repository, .github/workflows/deploy.yml:
name: deploy
on:
push:
branches: [main]
concurrency: deploy
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to server
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }}
SSH_USER: ${{ secrets.SSH_USER }}
run: |
install -m 600 /dev/null key
printf '%s\n' "$SSH_KEY" > key
ssh -i key -o StrictHostKeyChecking=accept-new "$SSH_USER@$SSH_HOST" '
set -e
cd /opt/app
git pull --ff-only
docker compose up -d --build
docker image prune -f
'concurrency: deploy keeps deploys from piling on top of each other when two pushes come in a row. --ff-only stops instead of merging if someone changed something on the server by hand, so there are no surprises.
Push and follow the process in the Actions tab. Once the check mark turns green, the change is already live.
Step 5: speed it up with an AI assistant
An AI assistant (Claude, ChatGPT, Copilot) can adapt all the files in this post to your own project in a few minutes. An example of a prompt that works:
"Write a multi-stage Dockerfile for this FastAPI project: a separate build stage, a slim final image, running as a non-root user, starting uvicorn on port 8000. Here is requirements.txt: ..."
A few rules save you time and keep you safe:
- Never paste secrets.
.env, a private key or a password must not end up in an AI chat. If needed, write a placeholder likeDATABASE_URL=.... - Give the whole error. Pasting the output of
docker compose logs app --tail 50gets you a result much faster than writing "it doesn't work". - Read the commands, then run them. Especially
rm,chmod -Rand firewall commands.
Step 6: when something breaks
docker compose ps # are the containers running
docker compose logs app --tail 50 # the application's latest log
docker compose logs caddy --tail 50 # certificate problems show up hereThe simplest rollback: git revert the faulty commit and push again. The workflow will build the previous working version by itself.
Short checklist
- The application does not run as root in the container.
.envis not in the repository or in the image.- The application port is not exposed to the outside; only 80 and 443 are open.
- There is a separate SSH key for deploys; your personal key is not on GitHub.
- The HTTPS certificate renews automatically.
- The rollback plan is clear:
git revertand push.
This setup works comfortably from a small project up to a mid-sized product. And the biggest gain is time: a deploy is no longer a separate job, but a natural continuation of git push.
A server in Baku means low latency for your users in Azerbaijan. At JezaHost a VPS is ready in a few minutes, and connecting a domain and a free SSL certificate are included in the portal.