Docker + PostgreSQL

Yes Lee
2 min readJan 11, 2019

--

Prerequisites

Install Docker

Goal

  1. Different OS, same docker image, same docker command.
  2. Able to connect to the database.

Run the official PostgreSQL image

docker pull postgres:11.1
docker images

Run the container

docker run \
-d \
--name db \
-p 5432:5432 \
--rm \
-v ~/docker/volumes/postgres:/var/lib/postgresql/data \
postgres:11.1

--detach, -d: Run container in background and print container ID
--name: Assign a name to the container
--publish, -p: Publish a container’s port(s) to the host
--rm: Automatically remove the container when it exits
--volume, -v: Bind mount a volume

docker ps

--

--

Yes Lee
Yes Lee

Written by Yes Lee

Frontend Engineer in Taiwan.

No responses yet