Prerequisites
Goal
- Different OS, same docker image, same docker command.
- 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
docker exec -it db bash
psql -h localhost -U postgres
docker stop db