DEV Community

Cover image for #016 Docker Databases
Omar
Omar

Posted on

#016 Docker Databases

Introduction

this is part 16 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


Docker and databases

This part will be very very short because we talk about volumes before.
but there is a Database special volume.
I am going to use official postgres image in this.
if we go to postgres official image.

postgres

docker run -d \
    --name some-postgres \
    -e POSTGRES_PASSWORD=mysecretpassword \
    -e PGDATA=/var/lib/postgresql/data/pgdata \
    -v /custom/mount:/var/lib/postgresql/data \
    postgres
Enter fullscreen mode Exit fullscreen mode

we have a new tag here -e we didn't talk about before and it's out of the scope for today but in case you a curious

help

docker run --help | grep -e,
Enter fullscreen mode Exit fullscreen mode

| grep is a linux/unix thing , | it's called pipeline it takes the output of the first and passed to the other program grep is a built in program to search for a text in our case it's -e

-e This is an environment variable that is not Docker specific. Because the variable is used by the postgres server binary

we see that postgres default place to save data is :/var/lib/postgresql/data , it's vary between databases reddis use another location , it depend on every database.

so -v /custom/mount:/var/lib/postgresql/data is our volume for postgres database.

again if you need to use any other database you should read documentation of docker image to see where it store here data.

Top comments (0)