Login or register    

Docker for Development

This post shows how to boot various servers in docker for development.

Postgres in Docker for development

You can run Postgres in a docker container during development and testing.

Download proper PostgreSQL docker image

The first step, download the proper PostgreSQL docker image:

sudo docker pull postgres:9.6.9-alpine

output:

Trying to pull repository docker.io/library/postgres ...
sha256:fa4cbc3af6bfcd4853c1ad4a54e91657015bf524cae6acd6ec074fef3efe4f15: Pulling from docker.io/library/postgres
ff3a5c916c92: Pull complete
05bfd6c2e788: Pull complete
55463cefa110: Pull complete
b1f67252c62d: Pull complete
69326bc076a5: Pull complete
86980f8c394c: Pull complete
2b9a434f47a2: Pull complete
f68d1b6b93d5: Pull complete
7adb1837b806: Pull complete
Digest: sha256:fa4cbc3af6bfcd4853c1ad4a54e91657015bf524cae6acd6ec074fef3efe4f15
Status: Downloaded newer image for docker.io/postgres:9.6.9-alpine

Create a new PostgreSQL container

Next create spin up a new container forwarding the postgres ports to localhost.

docker run --name development-postgres -d -p 5432:5432 postgres:9.6.9-alpine

Make yourself a Postgres Superuser (in my case russellballestrini):

$ psql --host=localhost --port 5432 --username postgres --command \
  "CREATE USER russellballestrini with SUPERUSER;"

Then you can create a database like:

$ psql --host=localhost --port 5432 --username postgres --command \
  "CREATE DATABASE myapp_db;"

clean up

docker stop development-postgres
docker rm development-postgres

Redis in Docker for development

You can run Redis in a docker container during development and testing.

The first step, download the proper Redis docker image:

docker pull redis

Next create spin up a new container forwarding the postgres ports to localhost.

docker run --name development-redis -d -p 6379:6379 redis

Comments

Leave a comment

Please login or register to leave a comment!