ServerHandbook live check: run log
------------------------------------------------------------------------------
Article https://serverhandbook.com/kb/docker-compose-ubuntu
Check scripts/live/checks/docker-compose-ubuntu.mjs (sha256 a22697ec7a2bfa5fc0522d2aaba1e2899d691b68442e42ee03a2a05df5efd73d)
Ran at 2026-11-19T23:00:47Z (433 s)
Result PASS, all 29 claims held
Tested on
System Ubuntu 26.04.1 LTS
Kernel 7.0.0-43-generic
Package docker-ce 5:29.10.0-1~ubuntu.26.04~resolute
Package docker-compose-plugin 5.8.0-1~ubuntu.26.04~resolute
Package postgres-image 17.12
Package adminer-image 5.5.1
Setup A fresh Ubuntu 26.04 server (a VM from Ubuntu’s cloud image) with Docker Engine from Docker’s apt repository, reached over SSH as the sudo user deploy (in the docker group).
Every version above was read from the server at run time. Passwords used on the
throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test
------------------------------------------------------------------------------
What the steps changed on the server (recorded before the first step and after the last)
Packages added (0)
Packages upgraded (0)
Packages removed (0)
Services enabled at boot (0)
Services disabled (0)
Listening sockets opened (1)
tcp 127.0.0.1:8080 docker-proxy
Listening sockets closed (0)
Files added in /etc (0)
Files changed in /etc (0)
Files removed from /etc (0)
Disk used on / (includes logs written during the run): +605.3 MB
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Claims (29), each with what the run saw
------------------------------------------------------------------------------
1. ok a bare Ubuntu 26.04 server box (web-server) starts
2. ok (setup) Docker is installed and deploy is in the docker group
| deploy sudo users docker
3. ok (every later command runs in ~/myapp)
| /home/deploy/myapp
4. ok compose.yaml is written
| services:
| db:
| image: postgres:17-alpine
| restart: unless-stopped
| environment:
| POSTGRES_DB: app
| POSTGRES_USER: app
| POSTGRES_PASSWORD: ${DB_PASSWORD}
| volumes:
| - db-data:/var/lib/postgresql/data
| healthcheck:
| test: ["CMD-SHELL", "pg_isready -U app -d app"]
| interval: 5s
| timeout: 3s
| retries: 10
|
| adminer:
| image: adminer:5
| restart: unless-stopped
| ports:
| - "127.0.0.1:8080:8080"
| depends_on:
| db:
| condition: service_healthy
|
| volumes:
| db-data:
5. ok (a 32-character random password)
6. ok .env is readable by deploy only (-rw-------)
| -rw------- 1 deploy deploy 45 Nov 19 23:03 .env
7. ok docker compose config --quiet: the file is valid
| valid
8. ok (plain `docker compose config` prints the file WITH the password filled in)
9. ok pull --quiet downloads both images, one "Pulled" line each instead of every layer
| Image postgres:17-alpine Pulling
| Image adminer:5 Pulling
| Image adminer:5 Pulled
| Image postgres:17-alpine Pulled
10. ok up -d creates the network and the volume and starts db, then adminer once db is Healthy
| Network myapp_default Creating
| Volume myapp_db-data Creating
| Volume myapp_db-data Created
| Network myapp_default Created
| Container myapp-db-1 Creating
| Container myapp-db-1 Created
| Container myapp-adminer-1 Creating
| Container myapp-adminer-1 Created
| Container myapp-db-1 Starting
| Container myapp-db-1 Started
| Container myapp-db-1 Waiting
| Container myapp-db-1 Healthy
| Container myapp-adminer-1 Starting
| Container myapp-adminer-1 Started
11. ok ps: db is "(healthy)", adminer on 127.0.0.1:8080
| NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
| myapp-adminer-1 adminer:5 "entrypoint.sh docke…" adminer 6 seconds ago Up Less than a second 127.0.0.1:8080->8080/tcp
| myapp-db-1 postgres:17-alpine "docker-entrypoint.s…" db 9 seconds ago Up 6 seconds (healthy) 5432/tcp
12. ok Adminer answers on 127.0.0.1:8080
|
Login - Adminer
13. ok port 8080 listens on 127.0.0.1 only, not on the public address
| LISTEN 0 4096 127.0.0.1:8080 0.0.0.0:*
14. ok a table with one row is created
| CREATE TABLE
| INSERT 0 1
15. ok logs db: the database is "ready to accept connections"
| db-1 | 2026-11-19 23:07:10.929 UTC [1] LOG: listening on Unix socket "/run/postgresql/.s.PGSQL.5432"
| db-1 | 2026-11-19 23:07:10.954 UTC [56] LOG: database system was shut down at 2026-11-19 23:07:10 UTC
| db-1 | 2026-11-19 23:07:10.980 UTC [1] LOG: database system is ready to accept connections
16. ok down removes the containers and the network
| Container myapp-adminer-1 Stopping
| Container myapp-adminer-1 Stopped
| Container myapp-adminer-1 Removing
| Container myapp-adminer-1 Removed
| Container myapp-db-1 Stopping
| Container myapp-db-1 Stopped
| Container myapp-db-1 Removing
| Container myapp-db-1 Removed
| Network myapp_default Removing
| Network myapp_default Removed
17. ok the volume myapp_db-data is still there
| DRIVER VOLUME NAME
| local myapp_db-data
18. ok after down and up, the row is still there
| t
| ------
| kept
| (1 row)
19. ok a password login over TCP works with the password from .env
| Container myapp-db-run-c2db3e2fbade Creating
| Container myapp-db-run-c2db3e2fbade Created
| ?column?
| ----------
| 1
| (1 row)
20. ok up -d recreates db with the new environment
| Container myapp-adminer-1 Running
| Container myapp-db-1 Recreate
| Container myapp-db-1 Recreated
| Container myapp-db-1 Starting
| Container myapp-db-1 Started
| Container myapp-db-1 Waiting
| Container myapp-db-1 Healthy
21. ok but the new password is refused: "password authentication failed for user "app""
| Container myapp-db-run-0c12784580b7 Creating
| Container myapp-db-run-0c12784580b7 Created
| psql: error: connection to server at "db" (172.18.0.2), port 5432 failed: FATAL: password authentication failed for user "app"
22. ok ALTER USER sets the new password inside the database: "ALTER ROLE"
| ALTER ROLE
23. ok now the new password works
| Container myapp-db-run-58c2964e1f34 Creating
| Container myapp-db-run-58c2964e1f34 Created
| ?column?
| ----------
| 1
| (1 row)
24. ok the server comes back after the reboot
| 14
25. ok after the reboot both containers are up again by themselves (restart: unless-stopped)
| NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
| myapp-adminer-1 adminer:5 "entrypoint.sh docke…" adminer 36 seconds ago Up 7 seconds 127.0.0.1:8080->8080/tcp
| myapp-db-1 postgres:17-alpine "docker-entrypoint.s…" db 28 seconds ago Up 7 seconds (healthy) 5432/tcp
26. ok and the data is there
| t
| ------
| kept
| (1 row)
27. ok (tested on) the box reports its OS, kernel and the version of 4 package(s)
| PRETTY_NAME="Ubuntu 26.04.1 LTS"
| VIRT=none
| KERNEL=7.0.0-43-generic
| PKG docker-ce 5:29.10.0-1~ubuntu.26.04~resolute
| PKG docker-compose-plugin 5.8.0-1~ubuntu.26.04~resolute
| postgres-image: postgres (PostgreSQL) 17.12
| adminer-image: version'>5.5.1
| version'>
28. ok down -v also removes the volume: "Volume myapp_db-data Removed"
| Container myapp-adminer-1 Stopping
| Container myapp-adminer-1 Stopped
| Container myapp-adminer-1 Removing
| Container myapp-adminer-1 Removed
| Container myapp-db-1 Stopping
| Container myapp-db-1 Stopped
| Container myapp-db-1 Removing
| Container myapp-db-1 Removed
| Volume myapp_db-data Removing
| Network myapp_default Removing
| Volume myapp_db-data Removed
| Network myapp_default Removed
29. ok the data is gone
| 0
------------------------------------------------------------------------------
Commands and what they printed (27)
------------------------------------------------------------------------------
$ mkdir ~/myapp && cd ~/myapp
$ cat > compose.yaml <<'EOF'
$ services:
$ db:
$ image: postgres:17-alpine
$ restart: unless-stopped
$ environment:
$ POSTGRES_DB: app
$ POSTGRES_USER: app
$ POSTGRES_PASSWORD: ${DB_PASSWORD}
$ volumes:
$ - db-data:/var/lib/postgresql/data
$ healthcheck:
$ test: ["CMD-SHELL", "pg_isready -U app -d app"]
$ interval: 5s
$ timeout: 3s
$ retries: 10
$
$ adminer:
$ image: adminer:5
$ restart: unless-stopped
$ ports:
$ - "127.0.0.1:8080:8080"
$ depends_on:
$ db:
$ condition: service_healthy
$
$ volumes:
$ db-data:
$ EOF
$ echo "DB_PASSWORD=$(openssl rand -hex 16)" > .env && chmod 600 .env
$ ls -l .env
-rw------- 1 deploy deploy 45 Nov 19 23:03 .env
$ docker compose config --quiet && echo valid
valid
$ docker compose pull --quiet
Image postgres:17-alpine Pulling
Image adminer:5 Pulling
Image adminer:5 Pulled
Image postgres:17-alpine Pulled
$ docker compose up -d
Network myapp_default Creating
Volume myapp_db-data Creating
Volume myapp_db-data Created
Network myapp_default Created
Container myapp-db-1 Creating
Container myapp-db-1 Created
Container myapp-adminer-1 Creating
Container myapp-adminer-1 Created
Container myapp-db-1 Starting
Container myapp-db-1 Started
Container myapp-db-1 Waiting
Container myapp-db-1 Healthy
Container myapp-adminer-1 Starting
Container myapp-adminer-1 Started
$ docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
myapp-adminer-1 adminer:5 "entrypoint.sh docke…" adminer 6 seconds ago Up Less than a second 127.0.0.1:8080->8080/tcp
myapp-db-1 postgres:17-alpine "docker-entrypoint.s…" db 9 seconds ago Up 6 seconds (healthy) 5432/tcp
$ curl -s http://127.0.0.1:8080/ | grep -o '[^<]*'
Login - Adminer
$ sudo ss -tln | grep ':8080 '
LISTEN 0 4096 127.0.0.1:8080 0.0.0.0:*
$ docker compose exec db psql -U app -d app -c "CREATE TABLE notes (t text); INSERT INTO notes VALUES ('kept');"
CREATE TABLE
INSERT 0 1
$ docker compose logs db --tail 3
db-1 | 2026-11-19 23:07:10.929 UTC [1] LOG: listening on Unix socket "/run/postgresql/.s.PGSQL.5432"
db-1 | 2026-11-19 23:07:10.954 UTC [56] LOG: database system was shut down at 2026-11-19 23:07:10 UTC
db-1 | 2026-11-19 23:07:10.980 UTC [1] LOG: database system is ready to accept connections
$ docker compose down
Container myapp-adminer-1 Stopping
Container myapp-adminer-1 Stopped
Container myapp-adminer-1 Removing
Container myapp-adminer-1 Removed
Container myapp-db-1 Stopping
Container myapp-db-1 Stopped
Container myapp-db-1 Removing
Container myapp-db-1 Removed
Network myapp_default Removing
Network myapp_default Removed
$ docker volume ls
DRIVER VOLUME NAME
local myapp_db-data
$ docker compose up -d
Network myapp_default Creating
Network myapp_default Created
Container myapp-db-1 Creating
Container myapp-db-1 Created
Container myapp-adminer-1 Creating
Container myapp-adminer-1 Created
Container myapp-db-1 Starting
Container myapp-db-1 Started
Container myapp-db-1 Waiting
Container myapp-db-1 Healthy
Container myapp-adminer-1 Starting
Container myapp-adminer-1 Started
$ docker compose exec db psql -U app -d app -c "SELECT * FROM notes;"
t
------
kept
(1 row)
$ docker compose run --rm --no-deps db sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -h db -U app -d app -c "SELECT 1"'
Container myapp-db-run-c2db3e2fbade Creating
Container myapp-db-run-c2db3e2fbade Created
?column?
----------
1
(1 row)
$ echo "DB_PASSWORD=$(openssl rand -hex 16)" > .env
$ docker compose up -d
Container myapp-adminer-1 Running
Container myapp-db-1 Recreate
Container myapp-db-1 Recreated
Container myapp-db-1 Starting
Container myapp-db-1 Started
Container myapp-db-1 Waiting
Container myapp-db-1 Healthy
$ docker compose run --rm --no-deps db sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -h db -U app -d app -c "SELECT 1"'
Container myapp-db-run-0c12784580b7 Creating
Container myapp-db-run-0c12784580b7 Created
psql: error: connection to server at "db" (172.18.0.2), port 5432 failed: FATAL: password authentication failed for user "app"
$ docker compose exec db sh -c "psql -U app -d app -c \"ALTER USER app PASSWORD '\$POSTGRES_PASSWORD'\""
ALTER ROLE
$ docker compose run --rm --no-deps db sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -h db -U app -d app -c "SELECT 1"'
Container myapp-db-run-58c2964e1f34 Creating
Container myapp-db-run-58c2964e1f34 Created
?column?
----------
1
(1 row)
$ sudo reboot
$ docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
myapp-adminer-1 adminer:5 "entrypoint.sh docke…" adminer 36 seconds ago Up 7 seconds 127.0.0.1:8080->8080/tcp
myapp-db-1 postgres:17-alpine "docker-entrypoint.s…" db 28 seconds ago Up 7 seconds (healthy) 5432/tcp
$ docker compose exec db psql -U app -d app -c "SELECT * FROM notes;"
t
------
kept
(1 row)
$ docker compose down -v
Container myapp-adminer-1 Stopping
Container myapp-adminer-1 Stopped
Container myapp-adminer-1 Removing
Container myapp-adminer-1 Removed
Container myapp-db-1 Stopping
Container myapp-db-1 Stopped
Container myapp-db-1 Removing
Container myapp-db-1 Removed
Volume myapp_db-data Removing
Network myapp_default Removing
Volume myapp_db-data Removed
Network myapp_default Removed
$ docker volume ls -q | grep -c db-data
0
------------------------------------------------------------------------------
Configuration files, read back from the server once they worked (2)
------------------------------------------------------------------------------
--- ~/myapp/compose.yaml
services:
db:
image: postgres:17-alpine
restart: unless-stopped
environment:
POSTGRES_DB: app
POSTGRES_USER: app
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- db-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app -d app"]
interval: 5s
timeout: 3s
retries: 10
adminer:
image: adminer:5
restart: unless-stopped
ports:
- "127.0.0.1:8080:8080"
depends_on:
db:
condition: service_healthy
volumes:
db-data:
--- ~/myapp/.env (the password was generated on the server with openssl rand -hex 16)
DB_PASSWORD=[password]
------------------------------------------------------------------------------
The check's source (scripts/live/checks/docker-compose-ubuntu.mjs)
As it ran.
------------------------------------------------------------------------------
/**
* KB how-to: run a two-container app with Docker Compose on Ubuntu 26.04 and 24.04 (--releases=26.04,24.04).
* PostgreSQL 17 (alpine) + Adminer 5 in ~/myapp: compose.yaml without the obsolete `version:` key, the password in a
* .env made with `openssl rand` and chmod 600 (so no password ever appears in a command), `config --quiet`, a
* healthcheck with depends_on: service_healthy, the web port on 127.0.0.1 only, `up -d`, ps, logs, data in a named
* volume surviving `down`, the POSTGRES_PASSWORD trap (changing it later does nothing to the existing database) and
* its fix, a reboot (restart: unless-stopped), then `down -v` deleting the data.
*
* Docker Engine is installed first exactly as the install article does it (hidden). The reader works in ~/myapp: a
* hidden `cd ~/myapp` line in ~/.bashrc puts every command there, as it would be for a reader in that folder, and a
* hidden COMPOSE_PROGRESS=plain keeps Compose's animated progress out of the captured output.
*/
import { rebootBox } from '../box.mjs'
import { bareBox, reportBox } from '../lib.mjs'
const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04'
const CODENAME = { '24.04': 'noble', '26.04': 'resolute' }[RELEASE]
const INSTALL = [
`echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4 >/dev/null`,
'sudo apt-get update -qq',
'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',
`printf 'Types: deb\\nURIs: https://download.docker.com/linux/ubuntu\\nSuites: ${CODENAME}\\nComponents: stable\\nArchitectures: amd64\\nSigned-By: /etc/apt/keyrings/docker.asc\\n' | sudo tee /etc/apt/sources.list.d/docker.sources >/dev/null`,
'sudo apt-get update -qq',
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin >/dev/null',
].join(' && ')
const COMPOSE = [
'services:',
' db:',
' image: postgres:17-alpine',
' restart: unless-stopped',
' environment:',
' POSTGRES_DB: app',
' POSTGRES_USER: app',
' POSTGRES_PASSWORD: ${DB_PASSWORD}',
' volumes:',
' - db-data:/var/lib/postgresql/data',
' healthcheck:',
' test: ["CMD-SHELL", "pg_isready -U app -d app"]',
' interval: 5s',
' timeout: 3s',
' retries: 10',
'',
' adminer:',
' image: adminer:5',
' restart: unless-stopped',
' ports:',
' - "127.0.0.1:8080:8080"',
' depends_on:',
' db:',
' condition: service_healthy',
'',
'volumes:',
' db-data:',
].join('\n')
// a login over the Compose network, as an app container makes it (inside the db container 127.0.0.1 is trusted by the
// image's pg_hba.conf, so a test there accepts any password: seen on the first 26.04 trial, 2026-11-20)
const TCP_LOGIN = `docker compose run --rm --no-deps db sh -c 'PGPASSWORD="[password]" psql -h db -U app -d app -c "SELECT 1"'`
const check = (ctx) =>
bareBox(ctx, async ({ sudoUser }) => {
const { run, L, keepConfig } = sudoUser()
L('sudo true')
L(INSTALL, 1800000)
L('sudo usermod -aG docker $USER')
ctx.check('(setup) Docker is installed and deploy is in the docker group', /\bdocker\b/.test(L('id -nG')), L('id -nG'))
// ── step 1: the project folder and compose.yaml ──────────────────────────────────────────
run('mkdir ~/myapp && cd ~/myapp', { id: 'mkdir' })
L("echo 'cd ~/myapp 2>/dev/null' >> ~/.bashrc")
// Compose draws animated progress on a terminal (one `up` captured 357,000 characters of spinner frames): plain
// progress prints the same status lines once each, which is what a reader's screen ends up showing
L("echo 'export COMPOSE_PROGRESS=plain' >> ~/.bashrc")
ctx.check('(every later command runs in ~/myapp)', L('pwd').endsWith('/myapp'), L('pwd'))
run(`cat > compose.yaml <<'EOF'\n${COMPOSE}\nEOF`, { id: 'compose' })
ctx.check('compose.yaml is written', L('cat compose.yaml') === COMPOSE, L('cat compose.yaml'))
// ── step 2: the password in .env ─────────────────────────────────────────────────────────
run('echo "DB_PASSWORD=$(openssl rand -hex 16)" > .env && chmod 600 .env', { id: 'env' })
const pw1 = L("cut -d= -f2 .env")
ctx.secret(pw1)
ctx.check('(a 32-character random password)', /^[0-9a-f]{32}$/.test(pw1), '')
const ls = run('ls -l .env', { id: 'ls-env' })
ctx.check('.env is readable by deploy only (-rw-------)', /^-rw------- 1 deploy deploy /.test(ls.out), ls.out)
const cfg = run('docker compose config --quiet && echo valid', { id: 'config' })
ctx.check('docker compose config --quiet: the file is valid', cfg.out === 'valid', cfg.out)
ctx.check('(plain `docker compose config` prints the file WITH the password filled in)', L('docker compose config').includes(pw1), '')
// ── step 3: start it ─────────────────────────────────────────────────────────────────────
const pull = run('docker compose pull --quiet', { id: 'pull', timeout: 1200000 })
ctx.check('pull --quiet downloads both images, one "Pulled" line each instead of every layer', pull.exit === 0 && /Image adminer:5 Pulled/.test(pull.out) && /Image postgres:17-alpine Pulled/.test(pull.out) && !/fs layer|Downloading/.test(pull.out), pull.out)
const up = run('docker compose up -d', { id: 'up', timeout: 600000 })
ctx.check('up -d creates the network and the volume and starts db, then adminer once db is Healthy', /Network myapp_default\s+Created/.test(up.out) && /Volume "?myapp_db-data"?\s+Created/.test(up.out) && /Container myapp-db-1\s+Healthy/.test(up.out) && /Container myapp-adminer-1\s+Started/.test(up.out), up.out)
const ps = run('docker compose ps', { id: 'ps' })
ctx.check('ps: db is "(healthy)", adminer on 127.0.0.1:8080', /myapp-db-1 .*\(healthy\)/.test(ps.out) && /127\.0\.0\.1:8080->8080\/tcp/.test(ps.out), ps.out)
const title = run(`curl -s http://127.0.0.1:8080/ | grep -o '[^<]*'`, { id: 'curl' })
ctx.check('Adminer answers on 127.0.0.1:8080', /Login - Adminer<\/title>/.test(title.out), title.out)
const ss = run("sudo ss -tln | grep ':8080 '", { id: 'ss' })
ctx.check('port 8080 listens on 127.0.0.1 only, not on the public address', /127\.0\.0\.1:8080/.test(ss.out) && !/(0\.0\.0\.0|\[::\]|\*):8080/.test(ss.out), ss.out)
// ── step 4: data, logs ───────────────────────────────────────────────────────────────────
const ins = run(`docker compose exec db psql -U app -d app -c "CREATE TABLE notes (t text); INSERT INTO notes VALUES ('kept');"`, { id: 'insert' })
ctx.check('a table with one row is created', /CREATE TABLE/.test(ins.out) && /INSERT 0 1/.test(ins.out), ins.out)
const logs = run('docker compose logs db --tail 3', { id: 'logs' })
ctx.check('logs db: the database is "ready to accept connections"', /database system is ready to accept connections/.test(logs.out), logs.out)
// ── step 5: down keeps the data ──────────────────────────────────────────────────────────
const down = run('docker compose down', { id: 'down' })
ctx.check('down removes the containers and the network', /Container myapp-db-1\s+Removed/.test(down.out) && /Network myapp_default\s+Removed/.test(down.out), down.out)
const vol = run('docker volume ls', { id: 'volume-ls' })
ctx.check('the volume myapp_db-data is still there', /myapp_db-data/.test(vol.out), vol.out)
run('docker compose up -d', { id: 'up-again', timeout: 300000 })
const sel = run(`docker compose exec db psql -U app -d app -c "SELECT * FROM notes;"`, { id: 'select' })
ctx.check('after down and up, the row is still there', /\bkept\b/.test(sel.out), sel.out)
// ── the POSTGRES_PASSWORD trap ───────────────────────────────────────────────────────────
const t0 = run(TCP_LOGIN, { id: 'tcp-ok' })
ctx.check('a password login over TCP works with the password from .env', /\(1 row\)/.test(t0.out), t0.out)
run('echo "DB_PASSWORD=$(openssl rand -hex 16)" > .env', { id: 'env-new' })
ctx.secret(L('cut -d= -f2 .env'))
const up2 = run('docker compose up -d', { id: 'up-new-password', timeout: 300000 })
ctx.check('up -d recreates db with the new environment', /Container myapp-db-1\s+(Recreated|Started|Healthy)/.test(up2.out), up2.out)
const t1 = run(TCP_LOGIN, { id: 'tcp-fail' })
ctx.check('but the new password is refused: "password authentication failed for user "app""', /password authentication failed for user "app"/.test(t1.out), t1.out)
const alter = run(`docker compose exec db sh -c "psql -U app -d app -c \\"ALTER USER app PASSWORD '\\$POSTGRES_PASSWORD'\\""`, { id: 'alter' })
ctx.check('ALTER USER sets the new password inside the database: "ALTER ROLE"', /ALTER ROLE/.test(alter.out), alter.out)
const t2 = run(TCP_LOGIN, { id: 'tcp-fixed' })
ctx.check('now the new password works', /\(1 row\)/.test(t2.out), t2.out)
// ── step 6: after a reboot ───────────────────────────────────────────────────────────────
const secs = rebootBox()
ctx.check('the server comes back after the reboot', typeof secs === 'number', String(secs))
let back = ''
for (let i = 0; i < 40 && !/healthy/.test(back); i++) {
L('sleep 5', 30000)
back = L('docker compose ps 2>/dev/null')
}
ctx.capture('sudo reboot', '', { id: 'reboot' })
const ps2 = run('docker compose ps', { id: 'ps-after-reboot' })
ctx.check('after the reboot both containers are up again by themselves (restart: unless-stopped)', /myapp-db-1 .*\(healthy\)/.test(ps2.out) && /myapp-adminer-1 .*Up/.test(ps2.out), ps2.out)
const sel2 = run(`docker compose exec db psql -U app -d app -c "SELECT * FROM notes;"`, { id: 'select-after-reboot' })
ctx.check('and the data is there', /\bkept\b/.test(sel2.out), sel2.out)
// the files as they are now that everything above worked (the page's "Configuration files" and /configs)
keepConfig('~/myapp/compose.yaml', { cmd: 'cat ~/myapp/compose.yaml' })
keepConfig('~/myapp/.env', { cmd: 'cat ~/myapp/.env', note: 'the password was generated on the server with openssl rand -hex 16' })
ctx.stepsDone()
reportBox(
ctx,
L,
`A fresh Ubuntu ${RELEASE} server (a VM from Ubuntu’s cloud image) with Docker Engine from Docker’s apt repository, reached over SSH as the sudo user deploy (in the docker group).`,
['docker-ce', 'docker-compose-plugin'],
[
{ name: 'postgres-image', cmd: 'docker compose exec db postgres --version', re: /(\d+\.\d+)/ },
{ name: 'adminer-image', cmd: `curl -s http://127.0.0.1:8080/ | grep -o "version.>[^<]*"`, re: /version.>\s*([\d.]+)/ },
],
)
// ── remove everything, data included ─────────────────────────────────────────────────────
const dv = run('docker compose down -v', { id: 'down-v' })
ctx.check('down -v also removes the volume: "Volume myapp_db-data Removed"', /Volume "?myapp_db-data"?\s+Removed/.test(dv.out), dv.out)
const vol2 = run('docker volume ls -q | grep -c db-data', { id: 'volume-gone' })
ctx.check('the data is gone', vol2.out.trim() === '0', vol2.out)
})
export default check