Postgres Docker

First we'll need to create a docker image for our database.

Note: If you're not familiar with Docker, and have pluralsight subscription, I highly recommend watching this docker deep-dive course by Nigel Poulton. This is a really great course and it gives a quick ramp up on docker, just enough to get started. There is also a plenty of other learning docker resources available. Anyway even without basic docker knowledge, you should be able to proceed with the tutorial.

Let's create a separate postgres directory inside project's root folder to keep track of database-related files. Now we can download postgres_create.sql script and save it under newly created postgres directory.

The db image will be based on the official postgres Docker image. On top of that, we'll run our postgres_create.sql script. This can be declared in the lines of following Dockerfile (create Dockerfile under postgres directory):

FROM postgres

COPY postgres_create.sql /docker-entrypoint-initdb.d/postgres_create.sql

The COPY instruction will place the script in a special directory inside the container, from which all scripts are run when the image is built.

With the script and Dockerfile in place, we can proceed to building the Docker image for database. Run following command from the root directory:

> docker build -t theimowski/suavemusicstore_db:0.1 postgres

The command will build database image with a theimowski/suavemusistore_db tag in version 0.1 using Dockerfile from postgres directory.

After running the script and typing docker images, you should spot the newly built image:

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE
theimowski/suavemusicstore_db   0.1                 45ac0e98f557        4 days ago          266 MB
postgres                        latest              ecd991538a0f        2 weeks ago         265 MB

To spin up a DB container from the image, simply type:

> docker run --name suavemusicstore_db -e POSTGRES_PASSWORD=mysecretpassword `
             -d -p 5432:5432 theimowski/suavemusicstore_db:0.1

Arguments to the above command are:

  • proper name of the container (--name <name>),
  • environment variable for Postgres password (-e <VAR>=<val>),
  • -d switch to indicate detached (background) mode,
  • mapped standard Postgres port 5432 from the container to host (-p <hostPort>:<containerPort>),
  • the tag of image (theimowski/suavemusicstore_db:0.1).

If everything went fine, we should be able to see a running container with the docker ps command:

CONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS              PORTS                    NAMES
a47a4917d6af        theimowski/suavemusicstore_db:0.1   "docker-entrypoint..."   47 hours ago        Up 4 seconds        0.0.0.0:5432->5432/tcp   suavemusicstore_db
type IntPath = PrintfFormat<(int -> string),unit,string,string,int>

Full name: SuaveMusicStore.Path.IntPath
Multiple items
type PrintfFormat<'Printer,'State,'Residue,'Result> =
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result>
member Value : string

Full name: Microsoft.FSharp.Core.PrintfFormat<_,_,_,_>

--------------------
type PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple> =
inherit PrintfFormat<'Printer,'State,'Residue,'Result>
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple>

Full name: Microsoft.FSharp.Core.PrintfFormat<_,_,_,_,_>

--------------------
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result>

--------------------
new : value:string -> PrintfFormat<'Printer,'State,'Residue,'Result,'Tuple>
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
type unit = Unit

Full name: Microsoft.FSharp.Core.unit
val withParam : key:string * value:string -> path:string -> string

Full name: SuaveMusicStore.Path.withParam
val key : string
val value : string
val path : string
val sprintf : format:Printf.StringFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
val home : string

Full name: SuaveMusicStore.Path.home
module Store

from SuaveMusicStore.Path
val overview : string

Full name: SuaveMusicStore.Path.Store.overview
val browse : string

Full name: SuaveMusicStore.Path.Store.browse
val details : IntPath

Full name: SuaveMusicStore.Path.Store.details
val browseKey : string

Full name: SuaveMusicStore.Path.Store.browseKey
namespace Suave
module Html

from Suave
val cssLink : href:string -> Node

Full name: SuaveMusicStore.View.cssLink
val href : string
val link : attr:Attribute list -> Node

Full name: Suave.Html.link
val h2 : s:string -> Node

Full name: SuaveMusicStore.View.h2
val s : string
val tag : tag:string -> attr:Attribute list -> contents:Node list -> Node

Full name: Suave.Html.tag
union case Node.Text: string -> Node
val ul : nodes:Node list -> Node

Full name: SuaveMusicStore.View.ul
val nodes : Node list
val li : (Node list -> Node)

Full name: SuaveMusicStore.View.li
val home : Node list

Full name: SuaveMusicStore.View.home
val store : genres:string list -> Node list

Full name: SuaveMusicStore.View.store
val genres : string list
val p : (Attribute list -> Node list -> Node)

Full name: Suave.Html.p
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member GetSlice : startIndex:int option * endIndex:int option -> 'T list
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val length : list:'T list -> int

Full name: Microsoft.FSharp.Collections.List.length
val genre : string
val url : string
module Path

from SuaveMusicStore
val a : href:string -> attr:Attribute list -> (Node list -> Node)

Full name: Suave.Html.a
val browse : genre:string -> Node list

Full name: SuaveMusicStore.View.browse
val details : id:int -> Node list

Full name: SuaveMusicStore.View.details
val id : int
val index : container:Node list -> string

Full name: SuaveMusicStore.View.index
val container : Node list
val html : (Attribute list -> Node list -> Node)

Full name: Suave.Html.html
val head : (Attribute list -> Node list -> Node)

Full name: Suave.Html.head
val title : attr:Attribute list -> s:string -> Node

Full name: Suave.Html.title
val body : (Attribute list -> Node list -> Node)

Full name: Suave.Html.body
val div : (Attribute list -> Node list -> Node)

Full name: Suave.Html.div
val htmlToString : node:Node -> string

Full name: Suave.Html.htmlToString
module App

from SuaveMusicStore
module Filters

from Suave
module Operators

from Suave
module RequestErrors

from Suave
module Successful

from Suave
module Web

from Suave
val html : container:Html.Node list -> WebPart

Full name: SuaveMusicStore.App.html
val container : Html.Node list
val OK : body:string -> WebPart

Full name: Suave.Successful.OK
module View

from SuaveMusicStore
val index : container:Html.Node list -> string

Full name: SuaveMusicStore.View.index
val browse : (HttpContext -> Async<HttpContext option>)

Full name: SuaveMusicStore.App.browse
val request : apply:(HttpRequest -> HttpContext -> 'a) -> context:HttpContext -> 'a

Full name: Suave.Http.request
val r : HttpRequest
member HttpRequest.queryParam : key:string -> Choice<string,string>
union case Choice.Choice1Of2: 'T1 -> Choice<'T1,'T2>
val browse : genre:string -> Html.Node list

Full name: SuaveMusicStore.View.browse
union case Choice.Choice2Of2: 'T2 -> Choice<'T1,'T2>
val msg : string
val BAD_REQUEST : body:string -> WebPart

Full name: Suave.RequestErrors.BAD_REQUEST
val webPart : WebPart<HttpContext>

Full name: SuaveMusicStore.App.webPart
val choose : options:WebPart<'a> list -> WebPart<'a>

Full name: Suave.WebPart.choose
val path : pathAfterDomain:string -> WebPart

Full name: Suave.Filters.path
val home : Html.Node list

Full name: SuaveMusicStore.View.home
val store : genres:string list -> Html.Node list

Full name: SuaveMusicStore.View.store
val pathScan : pf:PrintfFormat<'a,'b,'c,'d,'t> -> h:('t -> WebPart) -> WebPart

Full name: Suave.Filters.pathScan
val details : Path.IntPath

Full name: SuaveMusicStore.Path.Store.details
val details : id:int -> Html.Node list

Full name: SuaveMusicStore.View.details
val pathRegex : pathAfterDomainRegex:string -> WebPart

Full name: Suave.Filters.pathRegex
module Files

from Suave
val browseHome : WebPart

Full name: Suave.Files.browseHome
val startWebServer : config:SuaveConfig -> webpart:WebPart -> unit

Full name: Suave.Web.startWebServer
val defaultConfig : SuaveConfig

Full name: Suave.Web.defaultConfig

Show code from this section on GitHub

results matching ""

    No results matching ""