简体   繁体   中英

How do I connect to a postgres docker image with username, password, and url after running it?

Basically, I'm following my school assignment. It says to run a postgres image locally as so docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -p 5432:5432 postgres:11 . Then, it says I can connect to the database with the following info username: postgres , password: docker , url: jdbc:postgresql://localhost:5432/postgres . I've tried looking online, but can't find ways to do this in my command prompt (I'm on Windows). I'm wondering if this can only be refered to the Java code that I'm supposed to eventually do? Then it says I should create database and generate Jooq records: mvn clean package . There's a folder with some yaml and sql files. However, when I run this command, there's always a build failure.

Option 1 (dockerized).

Run

docker run --rm -it --net host postgres:11 psql -U postgres -h localhost -p 5432

and enter password docker when prompted.

Option 2 (native).

Download and install postgresql for windows from here: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

Then connect from PowerShell as following:

psql -U postgres -h localhost -p 5432

and enter password docker when prompted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM