Skip to Content
vVozoraDocs
Guides

Run Docker on Ubuntu with Nginx and HTTPS

Deploy a sample container, configure a host firewall, put Nginx and a certificate in front of it, and check it survives a reboot, on an Ubuntu 24.04 VPS.

Start with a small HTTP container, put Nginx in front of it, then add a certificate for a domain you control. Once that path works, replace the sample with your own application.

This walkthrough targets a fresh Ubuntu 24.04 LTS VPS with SSH access. The sample has no database or persistent user data. Your application's memory, storage, secrets and backup requirements will determine its eventual configuration.

Every command below, apart from requesting the certificate itself, was run on Ubuntu 24.04.5 on a Vozora Small on 13 November 2026, with Docker 29.9 and Nginx 1.24, including the reboot at the end. Requesting a certificate needs a public domain pointing at the server, which the test server did not have, so that one step follows Certbot's own documentation and was not run.

Before you start

Have your server's IPv4 address and SSH private key ready. The Ubuntu image signs you in as ubuntu; the login user is also shown on the server's Overview → Connect card. Use sudo for administrative commands.

You also need a domain or subdomain you control. This guide uses app.example.com as a placeholder. Replace it everywhere with one real name, and create its A record pointing to your VPS IPv4 address (you can host the domain on Vozora DNS, or use any DNS provider). Request a certificate only for names you have configured. Do not add a www name unless you also configure and test its DNS.

Check that the firewalls your server is in allow TCP 22, 80 and 443. The default firewall allows everything unless you have changed it.

Connect to your server

On your own computer, replace the address below:

ssh ubuntu@YOUR_SERVER_IPV4

On the VPS, check the operating system, wait for initial setup to finish, and confirm you can use sudo:

cat /etc/os-release
sudo cloud-init status --wait
sudo -n true && echo "sudo works"

Wait until cloud-init reports status: done before installing packages. If it reports a warning or error, use sudo cloud-init status --long to inspect the details and resolve them before continuing.

If SSH rejects the key, check the username and the key attached to the server before changing SSH server policy. Do not enable root login as a workaround for using the wrong account.

Install Docker and Nginx

Use Docker's own package repository for Ubuntu, as Docker's installation documentation describes, so that you get a current Docker and its Compose plugin:

sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin nginx

Both services start by themselves. Check them and run Docker's sample container:

sudo systemctl is-active docker nginx
sudo docker run --rm hello-world

The expected result is active twice and output that includes Hello from Docker!.

If Docker did not start, inspect its log:

sudo journalctl -u docker -n 50 --no-pager

Configure the host firewall

A fresh Ubuntu server has ufw installed and inactive. Check first:

sudo ufw status

Status: inactive is expected. If it is already active, add to its existing rules instead of replacing them.

Keep your SSH session open while configuring the firewall. Allow SSH before enabling it:

sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status

ufw enable warns that it may disrupt SSH connections; with the OpenSSH rule added first, it does not. The status should list OpenSSH, 80/tcp and 443/tcp, each for IPv4 and IPv6.

Open a second SSH connection from your computer and confirm it works before closing the first. If it fails, correct the rules using the existing session or the server's browser console.

Docker publishes container ports with its own firewall rules, which ufw does not filter. That is why the sample below binds its port to the loopback address only: nothing outside the server can reach it, whatever ufw says.

Run a sample container

This sample returns one line of text so you can check the connection from your browser through Nginx to Docker. The image digest pins the sample to a specific version.

sudo docker run -d \
  --name vozora-guide-check \
  --restart unless-stopped \
  --memory 64m \
  --cpus 0.5 \
  -p 127.0.0.1:5678:5678 \
  hashicorp/http-echo@sha256:fcb75f691c8b0414d670ae570240cbf95502cc18a9ba57e982ecac589760a186 \
  -text='Vozora deployment check'

curl --fail http://127.0.0.1:5678/
sudo docker ps

The response should be Vozora deployment check. Keep the 127.0.0.1: binding when adding the proxy; do not change it to 0.0.0.0 just to make a failed request work.

Put Nginx in front of the container

Create /etc/nginx/conf.d/vozora-guide.conf. Replace app.example.com in this file with your real name:

server {
    listen 80;
    listen [::]:80;
    server_name app.example.com;

    location / {
        proxy_pass http://127.0.0.1:5678;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

Check the configuration and reload:

sudo nginx -t
sudo systemctl reload nginx

Give the reload a second, then test the correct virtual host from the VPS:

curl --fail -H 'Host: app.example.com' http://127.0.0.1/

Run the next request from your own computer, using your real domain:

curl -4 --fail --max-time 10 http://app.example.com/

Check the exact response body, not just an HTTP 200 status. Welcome to nginx! means the request reached Nginx's default site, not your app: check the hostname, the loaded configuration and that the reload completed.

Add a certificate and check renewal

Install Certbot and its Nginx plugin from Ubuntu's own repository:

sudo apt-get install -y certbot python3-certbot-nginx
certbot --version

Confirm your real domain's A record resolves to this VPS and the external HTTP check returns the sample body. If the name also has an AAAA record, it must point at this server's IPv6 address.

Replace app.example.com below with the same name used in Nginx and DNS:

sudo certbot --nginx -d app.example.com --redirect

Review the prompts and use a contact address you monitor. Certbot requests the certificate and updates Nginx to serve it and to redirect HTTP to HTTPS.

From your computer:

curl -4 --fail --max-time 15 https://app.example.com/
curl -4 --head --max-time 15 http://app.example.com/
curl -4 --max-time 5 http://YOUR_SERVER_IPV4:5678/

HTTPS should return the sample text without bypassing certificate verification. HTTP should redirect to the same hostname over HTTPS. Direct app-port access should fail to connect. If that port returns the sample, inspect the Docker port binding before proceeding.

The package installs a timer that renews certificates. Check it, and test the renewal path:

systemctl is-active certbot.timer
systemctl list-timers certbot.timer
sudo certbot renew --dry-run

The timer should report active and the dry run should succeed. Keep DNS and network access in place for renewal, and monitor certificate expiry. See Certbot's renewal documentation.

Check the app after a reboot

Once the HTTPS setup has passed, reboot during a suitable moment. A reboot interrupts traffic:

sudo reboot

Reconnect and check:

sudo systemctl is-active docker nginx ufw certbot.timer
sudo ufw status
sudo docker ps
curl --fail -H 'Host: app.example.com' http://127.0.0.1/

All four should report active, the firewall should list the same rules, and the sample container should be running again within a minute of boot. Repeat the external HTTP, HTTPS and closed app-port checks from your computer. The container's restart policy does not restart a container that you deliberately stopped, and it does not restore lost application data.

Replace the sample with your app

Use your application's documented image version, port, resource requirements and health check. Configure secrets and persistent storage deliberately. This sample has no volumes, database migrations, upload storage, authentication, WebSocket configuration or application-specific proxy trust settings.

Back up the data your application needs and test a restore separately: see Backing up and restoring. Container restarts and server recovery are not backup tests. Set up application health and certificate expiry monitoring before relying on the service.

When the sample is no longer needed, remove only its named container and dedicated Nginx configuration, then validate and reload Nginx. If you created a VPS just for the exercise, delete it when finished: a stopped server is still charged.

Ready to choose a server for your app? Compare Vozora's UK VPS plans.

On this page

Vozora is a trading name of Bankside Technology Ltd, company no. 17253446.TermsPrivacysupport@vozora.io