Recent CVEs are a good reason to check how current your OpenMRS instance is. This guide covers patching the operating system, upgrading the OpenMRS 3 stack, and moving to a fresh CloudSOE image. The image runs on Ubuntu 26.04 LTS on both AWS and Azure. It doesn’t include PHP, so the PHP2Shell advisory doesn’t apply.

OpenMRS runs as the official Docker Compose stack in /opt/openmrs, with four containers: gateway, frontend, backend and db (MariaDB). The OpenMRS release is pinned by the TAG line in /opt/openmrs/.env. Your data lives in two Docker named volumes: openmrs_db-data holds the database and openmrs_openmrs-data holds the OpenMRS data directory.

What you can upgrade in place

ComponentIn place?How
Operating system (Ubuntu 26.04 packages, kernel)Yesapt update && apt upgrade, then reboot if asked (below)
Docker and Compose (docker.io, docker-compose-v2)YesUbuntu archive packages, updated by apt upgrade
nginx (HTTPS on 443)YesUbuntu archive package, updated by apt upgrade
OpenMRS 3 (gateway, frontend, backend)Yes, with a backupMove to a newer release’s compose file and TAG, then docker compose pull and up -d (below)
MariaDB (db container)Patch releases onlyFollow the release’s compose file. For a MariaDB major-version change, use a fresh image

Database migrations only run forward: once a newer backend has upgraded your database, an older release can’t use it. A snapshot is your only rollback.

Before you start: back up

This is patient data. Store backups encrypted, somewhere that meets your regulatory requirements.

1. Snapshot the disk

  • AWS: EC2 → Volumes → select the instance’s root volume → Actions → Create snapshot.
  • Azure: the VM → Disks → select the OS disk → Create snapshot.

The Docker volumes are on this disk, so the snapshot covers the database too. For a clean snapshot, stop the stack first (cd /opt/openmrs && sudo docker compose stop) and start it again afterwards (sudo docker compose start).

2. Dump the database and the data volume

The database passwords were rotated on first boot and are stored in /opt/openmrs/.env:

cd /opt/openmrs
mkdir -p ~/openmrs-backup

# 1. The database (MariaDB, database "openmrs")
DB_PASS=$(sudo grep '^OMRS_DB_PASSWORD=' .env | cut -d= -f2)
sudo docker compose exec -T db mysqldump -uopenmrs -p"$DB_PASS" \
  --single-transaction --routines openmrs \
  | gzip > ~/openmrs-backup/openmrs-db-$(date +%F).sql.gz

# 2. The OpenMRS data directory (attachments, complex obs, runtime settings)
DBIMG=$(sudo docker compose config --images | grep -im1 maria)
sudo docker run --rm -v openmrs_openmrs-data:/d -v ~/openmrs-backup:/backup \
  --entrypoint tar "$DBIMG" czf /backup/openmrs-data-$(date +%F).tgz -C /d .

# 3. The stack definition and pinned release
sudo cp docker-compose.yml .env ~/openmrs-backup/
sudo chown -R "$(whoami)" ~/openmrs-backup

The .env copy contains the database passwords, so keep ~/openmrs-backup private. Ship it off the instance before you upgrade.

Update the operating system

sudo apt update
sudo apt upgrade

This also updates Docker, Compose and nginx from the Ubuntu archive. When the Docker package updates, the daemon restarts and the OpenMRS containers come back on their own (restart policy unless-stopped). The backend then needs a few minutes before the login pages answer.

Check whether a reboot is needed (usually after a kernel update):

[ -f /var/run/reboot-required ] && cat /var/run/reboot-required
sudo reboot

After a reboot, Docker starts the stack again and nginx comes back on port 443. The one-time openmrs-firstboot service does not run again, because its marker /var/lib/openmrs-firstboot.done already exists. Allow a few minutes for the backend to start, then check everything works.

Automatic security updates

The CloudSOE build leaves Ubuntu’s standard unattended-upgrades setup as it is. Ubuntu cloud images normally have it turned on for security updates, but it never reboots for you. Check it with:

systemctl status unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades

Unattended-upgrades only patches Ubuntu packages. It never changes the OpenMRS container images.

Held packages

The image doesn’t hold any packages. If you added holds yourself, list them so you know what apt upgrade will skip:

apt-mark showhold

Don’t run an in-place release upgrade (do-release-upgrade) on this image. To move to a newer Ubuntu release, use a fresh image.

Upgrade OpenMRS

The image ships the newest stable OpenMRS reference application release available at build time. The release’s own docker-compose.yml is in /opt/openmrs, and the release tag is the TAG line in .env.

Know what you’re running

cd /opt/openmrs
sudo grep '^TAG=' .env                     # OpenMRS release, e.g. TAG=3.x.y
sudo docker compose config --images        # the four container images and their tags
cat /etc/cloudsoe-support.txt              # CloudSOE image build and version

Upgrade to a newer release

  1. Pick the target release from the release tags and read its release notes, especially any notes about database or module changes.
  2. Take the backups above.
  3. Fetch the new release’s compose file and compare it with yours:
cd /opt/openmrs
NEW=3.x.y                                  # the release you're moving to

sudo cp docker-compose.yml docker-compose.yml.bak-$(date +%F)
sudo cp .env .env.bak-$(date +%F)

sudo curl -fsSL -o docker-compose.yml.new \
  "https://raw.githubusercontent.com/openmrs/openmrs-distro-referenceapplication/$NEW/docker-compose.yml"
diff docker-compose.yml docker-compose.yml.new

Read the diff before going on:

  • The db image line. A MariaDB patch bump (for example 10.11.x) is fine. A major change (for example 10.11 to 11.x) is not a routine upgrade. Keep your current db image line, or move to a fresh image.
  • Published ports. The host nginx proxies HTTPS to the gateway on 127.0.0.1:80, so the gateway must stay on port 80.
  • Volume names. The volumes must stay openmrs-data and db-data, or the new containers start with empty data.
  1. Switch to the new release and roll it out:
sudo mv docker-compose.yml.new docker-compose.yml
sudo sed -i "s/^TAG=.*/TAG=$NEW/" .env

sudo docker compose pull
sudo docker compose up -d
sudo docker compose logs -f backend        # watch the database update; Ctrl+C to stop following

The backend runs its database updates on startup. These take from a few minutes to much longer, depending on how far you jump and how much data you have. Requests through the gateway return 502/504 until the backend is ready. Don’t restart the stack while the update is running.

  1. When the backend log settles and the login page loads, check everything works.

Keep .env as it is apart from the TAG line. It also holds the rotated database passwords, and the backend’s own copy of the database password in openmrs-runtime.properties (inside the openmrs-data volume) must keep matching them.

If the upgrade goes wrong

Because the database migrated forward, putting the old TAG back is not enough. Roll back by restoring the disk snapshot, or restore your SQL dump on the old release as described in step 4 of the fresh-image section.

Move to a fresh CloudSOE image

A fresh image gets you a newer OpenMRS release, a newer base OS and fresh container images in one step. The old instance stays untouched until you switch over.

1. Back up the old instance

Run the backup from Before you start, then copy it to your workstation:

scp -r ubuntu@<old-ip>:~/openmrs-backup ./openmrs-backup     # Azure: use your admin username

2. Launch the latest image

Launch a new instance from the current CloudSOE OpenMRS listing: AWS guide or Azure guide. Wait until first boot finishes (openmrs-bootstrap-status reaches 100%). The new instance has its own rotated database passwords in its own /opt/openmrs/.env. Keep those, and don’t copy the old .env over them.

3. Copy the backup across

scp -r ./openmrs-backup ubuntu@<new-ip>:~/

4. Restore on the new instance

Stop everything except the database, replace the baked demo database with your dump, then restore the data directory:

cd /opt/openmrs
ROOT_PASS=$(sudo grep '^MYSQL_ROOT_PASSWORD=' .env | cut -d= -f2)

# Stop the application containers; keep db running
sudo docker compose stop gateway frontend backend

# Replace the database with your dump
sudo docker compose exec -T db mysql -uroot -p"$ROOT_PASS" -e \
  "DROP DATABASE openmrs; CREATE DATABASE openmrs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
gunzip -c ~/openmrs-backup/openmrs-db-*.sql.gz \
  | sudo docker compose exec -T db mysql -uroot -p"$ROOT_PASS" openmrs

# Restore the data directory, keeping this instance's database settings and modules
DATA_TGZ=openmrs-data-YYYY-MM-DD.tgz      # the file name in ~/openmrs-backup
DBIMG=$(sudo docker compose config --images | grep -im1 maria)
sudo docker run --rm -v openmrs_openmrs-data:/d -v ~/openmrs-backup:/backup \
  --entrypoint tar "$DBIMG" xzf "/backup/$DATA_TGZ" -C /d \
  --exclude=./openmrs-runtime.properties --exclude=./modules

# Start the stack; the backend upgrades the restored database if this release is newer
sudo docker compose up -d
sudo docker compose logs -f backend

Excluding openmrs-runtime.properties matters. It holds the database password, and the new instance’s file already matches the new instance’s rotated passwords. Excluding modules keeps the modules that ship with the new release. If you installed extra modules yourself, add them again in the legacy admin UI (/openmrs).

You now log in with your old OpenMRS accounts and passwords, because they came back with the database. The new instance’s /opt/openmrs/default-openmrs-credentials.txt no longer applies, so delete it.

If you installed your own TLS certificate on the old instance, copy it to the paths named in /etc/nginx/sites-available/openmrs-https.conf and run sudo systemctl reload nginx.

5. Switch DNS or the IP

  • AWS: move the Elastic IP from the old instance to the new one (EC2 → Elastic IPs → Associate), or update your DNS A record.
  • Azure: move the static public IP to the new VM’s network interface, or update your DNS A record.
  • If a load balancer fronts OpenMRS, point its target or backend pool at the new instance.

6. Retire the old instance

Leave the old instance stopped (not deleted) for a few days while staff confirm the new one. Then terminate or delete it, and clean up the snapshots and backup files you no longer need, following your data-retention policy.

Check everything works

On the instance:

cd /opt/openmrs
sudo docker compose ps                   # gateway, frontend, backend, db: running; backend and db healthy
sudo grep '^TAG=' .env
systemctl status nginx

From your own machine (an Azure VM often can’t reach its own public IP), check the REST session endpoint over HTTPS. A JSON reply containing "authenticated" means the backend is serving:

curl -sk https://<public-ip>/openmrs/ws/rest/v1/session
curl -sk -u admin:<password> https://<public-ip>/openmrs/ws/rest/v1/session   # "authenticated":true

Finally, log in to the clinical app at https://<public-ip>/ and open a known patient record. Check that recent visits, observations and any attachments are there.

Next steps

  • Configure OpenMRS: the compose stack, file locations, TLS options and managing containers
  • Tips & tricks: backups, sizing, hardening and troubleshooting