Getting Started with Container Apps
Container Apps allows you to launch and run a container from directly within Postgres. Container Apps is currently in public beta on Crunchy Bridge. During public beta you may find issues and areas of possible improvement, we welcome you sharing all feedback with us as we progress towards making it generally available.
Getting started with Container Apps in Postgres
Container Apps is powered by a Crunchy Data extension
pgpodman. You can setup your database with the extension by running:
CREATE EXTENSION pgpodman;
Once you’ve setup the extension you can launch your first container. Below you’ll find an example for launching pgAdmin4 directly from within Postgres:
SELECT run_container('-dt -p 5433:80/tcp -e PGADMIN_DEFAULT_EMAIL="[email protected]" -e PGADMIN_DEFAULT_PASSWORD="myVeryGoodPassword" -e PGADMIN_LISTEN_PORT=80 docker.io/dpage/pgadmin4');
The above command has a few key pieces. The first is
-p which will expose the docker image to the public port (the first of the two 5433 values), and route it to the port the docker image is listening on in this case port 80. Then we export all of the relevant environment variables to start up the container:
PGADMIN_DEFAULT_EMAILis the default email for the initial account in pgAdmin4
PGADMIN_DEFAULT_PASSWORDis the default password for the initial account in pgAdmin4
PGADMIN_LISTEN_PORTis the port which the pgAdmin4 web application will start up on. This needs to match the second port in our earlier config.
And the final value is the specific docker image you want to launch. Once you’ve run the above you can now visit your pgAdmin4 app, which will be running on the hostname of your connection string at port 5433 - http://p.o7kabmt4wndjnp46exmkhvn634.db.postgresbridge.com:5433.
Common use cases for Container Apps with Postgres
We see three common use cases for Container Apps with Postgres on Crunchy Bridge:
- Turn key apps on top of Postgres databases (examples include pg_tileserv, postgraphile, PostgREST)
- Data reporting and visualization apps on top of your data (examples include pgAdmin4, Blazer)
- Running database monitoring agents right along side your instance (examples include DataDog, New Relic, pganalyze)
For many of the above we have a collection of recipes to help get you up and running with examples, but you’re not limited to just the examples above. Any public docker image can be run, if you feel some are particular great for Container Apps on Crunchy Bridge please reach out and we can explore adding it to our examples.
More with pgpodman
The pgpodman extension has a few other pieces included to help when working with Container Apps on Crunchy Bridge. The functions supported with pgpodman include:
SELECT run_container- Start a container within your database
SELECT list_containers(show_all boolean)- List all containers and status. By default assumes a false flag. With
show_allparameter as false it will list only running containers, true will list all containers both running and stopped.
SELECT stop_container(<container_id>)- Stop a running container, but leaves it on the filesystem.
SELECT container_status(<container_id>)- Show status of a container.
SELECT container_logs(<container_id>)- Show the logs from a container.
SELECT remove_container(<container_id>)- Remove a stopped container from the container list.
Currently Container Apps within Crunchy Bridge exposes 10 ports to you to launch containers on during the public beta. Ports
5442 are available to be exposed to the public internet.
Currently the filesystem is restricted to 2 GB of containers. In order effectively manage the size of containers we recommend
remove_container to free up space after stopping a container.
There are a number of examples we’ve provided within our docs to help you get started. If an example app you’re looking for isn’t here you can feel free to still run it yourself, and if you’d need help in the form of a quickstart let us know which app and well aim to get it documented.