PostgreSQL: Use Docker Compose for PostgreSQL 18 beta 1

This is how to use Docker Compose to start a PostgreSQL container using the 18beta1 version

PostgreSQL: Use Docker Compose for PostgreSQL 18 beta 1

PostgreSQL 17 still is the latest stable version. But if you want to see if your applications will also work with PostgreSQL 18, or if you're just curious, but you don't want to install the software on a system, you can try PostgreSQL 18 while still in beta.

This is my docker-compose.yml file:

  psql_18:
    image: postgres:18beta1
    hostname: psql_18
    restart: always
    environment:
      POSTGRES_PASSWORD: XxXxXxXx
    ports:
      - 5432:5432

The image has to be pulled:

# [+] Pulling 26/28
 ⠏ psql_18 [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿] 108.9MB / 111.9MB Pulling     4.0s
   ✔ 37259e733066 Already exists                               0.0s
   ✔ ad9bf12774e0 Already exists                               0.0s
   ✔ 6c7475e9a1eb Already exists                               0.0s
   ✔ fd3187d6acde Already exists                               0.0s
   ✔ 573b5990cac7 Already exists                               0.0s
   ✔ e0da14ecf374 Already exists                               0.0s
   ⠸ ff1334dd8987 Extracting      [>               ]  557.1kB/111.9MB                                                                             2.3s
   ✔ 75666b1dad95 Download complete                            0.3s
   ✔ 5306d7fa847c Download complete                            0.3s
   ✔ 70859039fb0a Download complete                            0.6s
   ✔ 5a28d4488e42 Download complete                            0.7s
   ✔ 037cabf8248c Download complete              

After that, we can start it:

#  ✔ Container postgresql-psql_18-1  Started               1.3s
psql_18-1  | selecting default time zone ... Etc/UTC
psql_18-1  | creating configuration files ... ok
psql_18-1  | running bootstrap script ... ok
psql_18-1  | performing post-bootstrap initialization ... ok
psql_18-1  | initdb: warning: enabling "trust" authentication for local connections
psql_18-1  | initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
psql_18-1  | syncing data to disk ... ok
psql_18-1  |
psql_18-1  |
psql_18-1  | Success. You can now start the database server using:
psql_18-1  |
psql_18-1  |     pg_ctl -D /var/lib/postgresql/18/docker -l logfile start
psql_18-1  |
psql_18-1  | waiting for server to start....2025-07-09 12:38:14.842 UTC [49] LOG:  starting PostgreSQL 18beta1 (Debian 18~beta1-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
psql_18-1  | 2025-07-09 12:38:14.845 UTC [49] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
psql_18-1  | 2025-07-09 12:38:14.856 UTC [55] LOG:  database system was shut down at 2025-07-09 12:38:14 UTC
psql_18-1  | 2025-07-09 12:38:14.862 UTC [49] LOG:  database system is ready to accept connections
psql_18-1  |  done
psql_18-1  | server started
psql_18-1  |
psql_18-1  | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
psql_18-1  |
psql_18-1  | waiting for server to shut down...2025-07-09 12:38:14.961 UTC [49] LOG:  received fast shutdown request
psql_18-1  | .2025-07-09 12:38:14.965 UTC [49] LOG:  aborting any active transactions
psql_18-1  | 2025-07-09 12:38:14.969 UTC [49] LOG:  background worker "logical replication launcher" (PID 58) exited with exit code 1
psql_18-1  | 2025-07-09 12:38:14.969 UTC [53] LOG:  shutting down
psql_18-1  | 2025-07-09 12:38:14.972 UTC [53] LOG:  checkpoint starting: shutdown immediate
psql_18-1  | 2025-07-09 12:38:14.984 UTC [53] LOG:  checkpoint complete: wrote 0 buffers (0.0%), wrote 3 SLRU buffers; 0 WAL file(s) added, 0 removed, 0 recycled; write=0.003 s, sync=0.002 s, total=0.015 s; sync files=2, longest=0.001 s, average=0.001 s; distance=0 kB, estimate=0 kB; lsn=0/17581B8, redo lsn=0/17581B8
psql_18-1  | 2025-07-09 12:38:14.998 UTC [49] LOG:  database system is shut down
psql_18-1  |  done
psql_18-1  | server stopped
psql_18-1  |
psql_18-1  | PostgreSQL init process complete; ready for start up.
psql_18-1  |
psql_18-1  | 2025-07-09 12:38:15.090 UTC [1] LOG:  starting PostgreSQL 18beta1 (Debian 18~beta1-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
psql_18-1  | 2025-07-09 12:38:15.090 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
psql_18-1  | 2025-07-09 12:38:15.090 UTC [1] LOG:  listening on IPv6 address "::", port 5432
psql_18-1  | 2025-07-09 12:38:15.095 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
psql_18-1  | 2025-07-09 12:38:15.102 UTC [69] LOG:  database system was shut down at 2025-07-09 12:38:14 UTC
psql_18-1  | 2025-07-09 12:38:15.108 UTC [1] LOG:  database system is ready to accept connections

PostgreSQL 18 Beta 1 is now available and can be used - either by just running psql from within the container:

# docker exec -u postgres -ti postgresql-psql_18-1 psql
psql (18beta1 (Debian 18~beta1-1.pgdg120+1))
Type "help" for help.

postgres=# \l
                                                    List of databases
   Name    |  Owner   | Encoding | Locale Provider |  Collate   |   Ctype    | Locale | ICU Rules |   Access privileges
-----------+----------+----------+-----------------+------------+------------+--------+-----------+-----------------------
 postgres  | postgres | UTF8     | libc            | en_US.utf8 | en_US.utf8 |        |           |
 template0 | postgres | UTF8     | libc            | en_US.utf8 | en_US.utf8 |        |           | =c/postgres          +
           |          |          |                 |            |            |        |           | postgres=CTc/postgres
 template1 | postgres | UTF8     | libc            | en_US.utf8 | en_US.utf8 |        |           | =c/postgres          +
           |          |          |                 |            |            |        |           | postgres=CTc/postgres
(3 rows)

... or by connecting to the exposed port:

psql -U postgres -p 5432 -h mwe01
Password for user postgres: <password>
psql (17.5 (Ubuntu 17.5-1.pgdg24.04+1), server 18beta1 (Debian 18~beta1-1.pgdg120+1))
WARNING: psql major version 17, server major version 18.
         Some psql features might not work.
Type "help" for help.

postgres=#

Happy testing 😄

Disclaimer:

  • Don't use this version for your production data!
  • Keep in mind that after updating to a newer image, like 18beta2, your data might be lost (this was the case with 17 beta)

Subscribe to Martin's Blog

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe