cancel
Showing results for 
Search instead for 
Did you mean: 

Docker EPAS Quickstart

EDB Team Member

Objective

Create a super simple Docker container for running a default installation of EDB Postgres.
 
Prerequisites
Have Docker installed and working.
 
Components
  1. Dockerfile - special file that contains the recipe for building a Docker image
  2. Docker image - the result of building a docker file, can stay in your local Docker registry or can be exported elsewhere as a tar file
  3. Docker container - the result of running a Docker image, sort of like a running VM
 
Steps
 
mkdir -v ~/docker/epas
cd ~/docker/epas
vi Dockerfile
 
 

Here is what to put in your Dockerfile:

 
# This is my EPAS Dockerfile
#
 
#
# Docker images based on latest CentOS version
#
FROM centos:latest
 
#
# My email address as the maintainer of this Docker image
#
MAINTAINER <email address>
 
#
# Commands to install and setup EPAS, done in a single RUN command
# so as not to create unnecessary layers (Google this for more details
# about Docker image layers)
#
  && export YUM_USER=<yum user> \
  && export YUM_PASSWORD=<yum password> \
  && sed -i "s/<username>:<password>/$YUM_USER:$YUM_PASSWORD/g" /etc/yum.repos.d/edb.repo \
  && sed -i "\/ppas95/,/gpgcheck/ s/enabled=0/enabled=1/" /etc/yum.repos.d/edb.repo \
  && yum -y install ppas95-server 
 
#
# Set the user to be enterprisedb at this point
#
USER enterprisedb
 
#
# Initialize the cluster datadir with a default enterprisedb password of "enterprisedb"
# and Setup pg_hba.conf to allow connections with passwords by adding a catchall
# line at the end of the file
#
RUN echo "enterprisedb" > /tmp/password \
   && /usr/ppas-9.5/bin/initdb -D /var/lib/ppas/9.5/data --pwfile=/tmp/password \
   && echo "host   all   all   0.0.0.0/0   md5" >> /var/lib/ppas/9.5/data/pg_hba.conf
 
#
# Default command which will start Postgres in this container
#
CMD ["/usr/ppas-9.5/bin/edb-postgres", "-D", "/var/lib/ppas/9.5/data", "-h", "*"]
 
 

Now continuing with steps...

 
#
# Build the Dockerfile into a Docker image, don't forget the '.' specifying
# the directory of the Dockerfile as current directory.  This will do 
# a bunch of stuff, basically running all the steps in the Dockerfile
# to create the image.
#
docker build -t my-repo/epas:9.5 .
 
#
# Now let's start the EPAS container in interactive terminal so we
# can see the STDOUT
#
docker run -it  my-repo/epas:9.5 
 
#
# Congrats!  You started the EPAS container.  Now let's kill it
# and start it in the background as a daemon with a name.
#
<ctrl>-C
docker run -d --name epas my-repo/epas:9.5
docker ps
 
 
#
# Nice, your EPAS container is running.  Now, let's exec a command
# inside the container to connect to the database with psql.
#
docker exec -it epas /usr/ppas-9.5/bin/psql -d edb
\conninfo
exit
 
# That is pretty nice, but not so good if we can only connect to EPAS
# from inside the container.  How do we export the port so that someone
# outside the container can connect to EPAS?  Not hard at all, we just
# map the port inside the container to a port on the host.  So, let's
# kill our current container and restart with a port mapping.
#
docker rm -f epas
 
#
# Start the container mapping port 5444 on the Docker host to port 5444
# inside the container.
#
docker run -d --name epas -p 5444:5444 my-repo/epas:9.5
 
#
# Now we can connect to the EPAS database from the host via psql or
# your database client of choice.
#
psql -p 5444 -d edb -U enterprisedb
 

 

Congratulations!  You've created your first Docker container for EPAS.  This is just the beginning though.  Docker allows specifying "volumes" so that your container can leverage shared storage.  We can also make the container "smart" so that it starts as a master or starts as a replica of another database.  More to come in future quickstarts.