- install Docker Desktop from https://www.docker.com/get-started based on your OS.
- create your Docker account at https://hub.docker.com and log on.
- open a command window (in Windows), and type docker --version to check the docker version.
- c:\users\testuser>docker --version
- Docker version 19.03.8, build afacb8b
- start Docker Desktop and log on your Docket account.
- search postgres from https://hub.docker.com and click postgres Office Image.
- in the command window, type "docker pull postgres" to get the latest PostgreSQL image. Note: by default, the PostgreSQL version is the latest. To get a particular version, execute "docker pull postgres:12.2".
- in the command window, type the following to create and start a PostgreSQL container (-p for port number <trigger port #:port# in container>):
- docker run --name containername -h localhost -p 5435:5432 -e POSTGRES_PASSWORD=mypassword -d postgres:12.2
- use "docker ps" or "docker container ls" to show the running container status. "docker ps -a" lists all existing containers.
- to stop a docket container, type "docker stop containername"
- to restart an existing container, type "docker start containername"
- get in the docker container by typing "docker exec -it containername bash"
- within the container bash shell, you can then log in PostgreSQL as usual
- psql -U postgres postgres
- if you specified host and port numbers when creating the docker postgres container, you can access from the local machine using postgres client
- psql -h localhost -p 5435 -U postgres -W
- to remove the container, use "docker rm -f containername"
- to list docker images, type "docker images" or "docker image ls"
- to remove an image by name, use "docker image rm -f imagename", or by id using "docker image rmi -f 93d5585e579d"
Wednesday, May 6, 2020
How to create a Docker container for PostgreSQL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment