DEV Community

ERINFOLAMI PETER
ERINFOLAMI PETER

Posted on

APACHE AGE: Getting Started Part 3(AGE INSTALLATION VIA DOCKER)

Introduction

In the last article from the apache age series, we've been able to successfully install the apache age extension through installation directly from the source code on github. But you can also use the extension on your local machine through docker, this way you get to isolate the extension only on the docker container you spin up, and also wouldn't have to bother about barely installing a lot of dependencies on your local machine.

Pre-requisite

The pre-requisites remain the same which is having a compatible version(11) of postgreSQL installed (check here for guide) and also having docker installed on your local machine.

Note: It's recommended to use a linux environment.

Setting up and Installation

To install the age extension via docker is very easy. Once you have your pre-requisites installed follow this steps:

1. Pull the apache/age image from docker repository

docker pull apache/age
Enter fullscreen mode Exit fullscreen mode

This may take several minutes, based on your internet connectivity.

2. Run the apache/age container

docker run \
    --name myPostgresDb  \
    -p 5455:5432 \
    -e POSTGRES_USER=postgresUser \
    -e POSTGRES_PASSWORD=postgresPW \
    -e POSTGRES_DB=postgresDB \
    -d \
    apache/age
Enter fullscreen mode Exit fullscreen mode

You can change the following names (myPostgresDb, postgresUser, postgresPW, postgresDB) to suit your preference but make sure you remember them.

3. Confirm the container is running
After running the command in the previous steps leaving all the arguments as they are. I can now confirm my docker container is running

ceejay@ceejay:~$ docker ps

CONTAINER ID   IMAGE        COMMAND                  CREATED         STATUS         PORTS                                       NAMES

6ea0a9f55c3e   apache/age   "docker-entrypoint.sā€¦"   6 seconds ago   Up 4 seconds   0.0.0.0:5455->5432/tcp, :::5455->5432/tcp   myPostgresDb

ceejay@ceejay:~$ 

Enter fullscreen mode Exit fullscreen mode

4. Connect to the postgres cli running on the container

ceejay@ceejay:~$ docker exec -it myPostgresDb bash

root@6ea0a9f55c3e:/# psql -d postgresDB -U postgresUser

psql (11.19 (Debian 11.19-1.pgdg100+1), server 11.13 (Debian 11.13-1.pgdg100+1))

Type "help" for help.



postgresDB=#
Enter fullscreen mode Exit fullscreen mode

The docker exec connects to the running container, and the psql command connects to the postgres cli running on the container, the -d flag allows you to specify the database name, and the -U flags allows you to specify the username.
note: Remember to fill in the arguments according to what you set previously.

5. Load the Age extension
Now that we've successfully connected to the psql cli, we can now load in the age extension and also adding ag_catalog to search_path

postgresDB=# LOAD 'age';

LOAD

postgresDB=# SET search_path = ag_catalog, "$user", public;

SET

postgresDB=# 

Enter fullscreen mode Exit fullscreen mode

Now we can start creating our graphs and running cypher queries.

Conclusion

With the aid of docker you can run the age extension in isolation, anytime you need to access the extension all you need to do is connect to the postgres cli on the container as shown earlier and run your queries. See you in the next episode!.

Top comments (0)