PostgreSQL¶
PostgreSQL is a container based image.
Base Image¶
Base images can be obtained from Docker Hub.
Import image¶
Pull the image through Sherpa, giving the image reference with its tag:
sherpa server image pull --model postgresql_db --repo postgres:17
Sherpa records the version (17) and the repo it was pulled from (postgres). A node with
that version runs that repo, unless it sets image in the manifest. An image already pulled
with the docker CLI is not known to Sherpa until it is scanned. postgresql_db has no built-in repo,
so give the scan the model and the repo, without a tag; it records each local tag of the repo as
a version, with that repo:
docker pull postgres:17
sherpa server image scan --kind container --model postgresql_db --repo postgres
Default Node Parameters¶
| Property | Value |
|---|---|
| Kind | Container |
| CPU | Not limited |
| RAM | Not limited |
| ZTP | disabled |
| Management Interface | eth0 |
| Interface Driver | macvlan |
Example Manifest¶
name = "postgresql"
[[nodes]]
name = "db01"
model = "postgresql_db"
version = "17"
environment_variables = [
"POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password",
]
[[nodes.provisioners]]
type = "container"
[[nodes.provisioners.files]]
src = "secrets/postgres-password"
name = "postgres_password"
Put the password in secrets/postgres-password, next to the manifest, before sherpa up.
Superuser Password¶
The postgres image refuses to start without a password for the postgres superuser, and the
container exits at once. Sherpa sets none for postgresql_db, so the node needs one of these in
environment_variables:
| Variable | Effect |
|---|---|
POSTGRES_PASSWORD_FILE |
Password read from a file, as in the example. |
POSTGRES_PASSWORD |
Password given as the value. |
POSTGRES_HOST_AUTH_METHOD=trust |
No password is set or asked for. Anyone who reaches the node can log in as any user, including postgres. |
The example passes the password as a file with the
container provisioner, so it is not stored
with the lab. POSTGRES_PASSWORD is simpler, but the password is then saved on the Sherpa
server and shown by docker inspect; see
environment_variables.
The variables only take effect the first time the container starts, when PostgreSQL creates its
data directory. The image also accepts POSTGRES_USER and POSTGRES_DB to name the superuser
and the default database. See the image's documentation
for the full list.
Node Access¶
sherpa ssh <node-name>
docker exec -it <node-name>-<lab-id> sh
docker exec -it <node-name>-<lab-id> psql -U postgres
Notes¶
- Approximate time for the system to be ready:
1 minute