Docker

Download and run image

1) Check version:

docker --version
# Docker version 20.10.23, build 7155243

2) Download the Docker image for Postgres using the command:

docker pull postgres

3) Check that the image has been successfully downloaded using the command:

docker images

4) Run the Postgres container using the command:

docker run --name pgsql -e POSTGRES_PASSWORD='P@$$w0rd' -p 5432:5432 -d postgres
Description where: - `--name` sets the name of the container, - `-e` defines an environment variable, - `-p` configures port forwarding, and - `-d` specifies that the container should be run in detached mode

1) Check that the container is running using the command:

docker ps

1) Connect to the Postgres container using the command:

psql -h localhost -p 5432 -U postgres

1) If the container has been stopped, check its status using the command:

docker ps -a

1) If the container has been stopped, start it using the command:

docker start pgsql